Question

I'm rather new to PySide, and Qt in general. I want to add a QProgressBar to a QMessageBox where the buttons would usually be. I'm hoping that there's some way to subclass QMessageBox and change it's layout, but I've never done a Qt layout in code, I've done everything with Qt Designer and pyside-uic.

I've created a concept in Qt Designer, I'd like to have something similar to this done by sub-classing QMessageBox. I've looked at QProgressDialog, but it's too inflexible. I'd like to be able to use the QMessageBox Icon enum for the icon.

Concept

Was it helpful?

Solution

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()

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

OTHER TIPS

you can always add your own layout to the QProgressDialog.

layout = QtGui.QHBoxLayout()
self.setLayout(layout)

# layout.setContentsMargins(0, 0, 0, 0)
layout.setAlignment(QtCore.Qt.AlignTop)

icon = QtGui.QApplication.style().standardIcon(QtGui.QStyle.SP_FileIcon)
self.label = QtGui.QLabel()
self.label.setPixmap(icon.pixmap(16, 16))
self.label2 = QtGui.QLabel("My Label")
layout.addWidget(self.label)
layout.addWidget(self.label2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top