我确实在Qt Designer MainWindow Form和WidgetForm中创建了。
在MainWindow表单中,我确实添加了Mdi Area。
单击菜单选项后,如何在MdiArea中打开“设备小部件表单”?


  我的main.py


from windows.devices import Ui_Form_device

 class Ui_MainWindow(object):

    def Devices(self):
        self.Form_device = QtWidgets.QWidget()
        self.ui = Ui_Form_device()
        self.ui.setupUi(self.Form_device)
        self.Form_device.show()

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(823, 681)

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        MainWindow.setCentralWidget(self.centralwidget)
        self.centralwidget.setLayout(QtWidgets.QVBoxLayout(self.centralwidget))
        self.mdiArea = QtWidgets.QMdiArea(self.centralwidget)
        self.centralwidget.layout().addWidget(self.mdiArea)
        ...

        # menu : DEVICES
        self.actionDevices = QtWidgets.QAction(MainWindow)
        self.actionDevices.setObjectName("actionDevices")
        self.actionDevices.triggered.connect(self.Devices)

        ...


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())



  devices.py


class Ui_Form_device(object):
    def setupUi(self, Form_device):
        Form_device.setObjectName("Form_device")
        Form_device.resize(400, 300)
        self.label = QtWidgets.QLabel(Form_device)
        self.label.setGeometry(QtCore.QRect(100, 150, 111, 16))

最佳答案

尝试通过调用mdiArea.addSubWindow()如下所示:

def Devices(self):
    self.Form_device = QtWidgets.QWidget()
    self.ui = Ui_Form_device()
    self.ui.setupUi(self.Form_device)
    self.mdiArea.addSubWindow(self.Form_Device)

关于python - PyQt5-单击菜单选项后,在MDI区域中打开小部件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49645398/

10-09 01:48