如何继承QMessageBox并在PySide中添加进度栏

ron*_*975 3 python qt pyside qmessagebox progress-bar

我对PySide和Qt相当陌生。我想将QProgressBar添加到通常将在其中的按钮的QMessageBox中。我希望有某种方法可以继承QMessageBox并更改其布局,但是我从未在代码中进行过Qt布局,我已经使用Qt Designer和pyside-uic完成了所有工作。

我已经在Qt Designer中创建了一个概念,我想通过对QMessageBox进行子类化来实现类似的功能。我看过QProgressDialog,但是太不灵活了。我希望能够对图标使用QMessageBox Icon枚举。

概念

Rom*_*rev 5

QMessageBox uses a QGridLayout. So, you can add your QProgressBar to its layout:

msgBox = QMessageBox( QMessageBox.Warning, "My title", "My text.", QMessageBox.NoButton )

# Get the layout
l = msgBox.layout()

# Hide the default button
l.itemAtPosition( l.rowCount() - 1, 0 ).widget().hide()

progress = QProgressBar()

# Add the progress bar at the bottom (last row + 1) and first column with column span
l.addWidget(progress,l.rowCount(), 0, 1, l.columnCount(), Qt.AlignCenter )

msgBox.show()
Run Code Online (Sandbox Code Playgroud)

You can also remove the buttons msgBox.setStandardButtons( QMessageBox.NoButton ). But the close button will be disabled, too...