gpt4 book ai didi

python - PyQt5 - 单击菜单选项后在 MDI 区域中打开小部件

转载 作者:行者123 更新时间:2023-12-01 02:00:55 24 4
gpt4 key购买 nike

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

My 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/

24 4 0