Pyside Make Qdialog Appear In Main Window
I've created an app which has an main window and the possibility to open an dialog (question, error and so on). I'm not using QMessageBox.warning() or QMessageBox.question() and so
Solution 1:
The solution was quite simple: Passing an reference of QMainWindow
to the constructor of QDialog
will do the job, e.g:
classMessageBox(QtGui.QDialog):def__init__(self, parent, title, message, icon="info"):
super(MessageBox, self).__init__(parent)
...
and then calling the dialog from an class that inherits from QMainWindow
:
classMainWindow(QtGui.QMainWindow):def__init__(self):
super(MainWindow, self).__init__()
#connect button with function, e.g.:
mybutton.clicked.connect(self.open_dialog)
defopen_dialog(self):
MessageBox(self)
Maybe this helps anyone!
Solution 2:
If you set the parent of the QDialog
to the window, it will only show as one item on the task bar. This is generally the first argument to QMessageBox
.
classMessageBox:def__init__(self, parent, title, message):
msg = QtGui.QMessageBox(parent)
Also, if you really want to create a custom dialog, you might as well just subclass from QDialog
.
Post a Comment for "Pyside Make Qdialog Appear In Main Window"