PyQt Main Window vs. Dialog

前端 未结 1 1861
礼貌的吻别
礼貌的吻别 2021-01-14 14:29

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 someth

相关标签:
1条回答
  • 2021-01-14 15:11

    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")
    
    0 讨论(0)
提交回复
热议问题