Skip to content Skip to sidebar Skip to footer

PyQt Main Window Vs. Dialog

Probably a silly noob question, but here it is (condensed example): I've got some basic code to create a QDialog. in practice this is working well and I have something that creates

Solution 1:

From the doc:

Note: Creating a main window without a central widget is not supported. You must have a central widget even if it is just a placeholder.

so the central widget should be created and set up:

    def __init__(self):
        super(Window, self).__init__()

        # Button to load data
        self.LoadButton = QtGui.QPushButton('Load Data')
        # Button connected to `plot` method
        self.PlotButton = QtGui.QPushButton('Plot')

        # set the layout
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.LoadButton)
        layout.addWidget(self.PlotButton)

        # setup the central widget
        centralWidget = QtGui.QWidget(self)
        self.setCentralWidget(centralWidget)
        centralWidget.setLayout(layout)

        self.setGeometry(100,100,500,300)
        self.setWindowTitle("UI Testing")

Post a Comment for "PyQt Main Window Vs. Dialog"