Skip to content Skip to sidebar Skip to footer

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:

class MessageBox(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:

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        #connect button with function, e.g.:
        mybutton.clicked.connect(self.open_dialog)

   def open_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.

class MessageBox:
    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"