我正在使用pyqt4在python中构建文本编辑器,我想在mdi区域添加子窗口,每次点击new(菜单项)时都应包含QTextEdit。所以,我想知道如何实现这一点
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.gridLayout = QtGui.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.mdiArea = QtGui.QMdiArea(self.centralwidget)
self.mdiArea.setObjectName(_fromUtf8("mdiArea"))
self.gridLayout.addWidget(self.mdiArea, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName(_fromUtf8("menubar"))
self.menuFile = QtGui.QMenu(self.menubar)
self.menuFile.setObjectName(_fromUtf8("menuFile"))
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.actionNew = QtGui.QAction(MainWindow)
self.actionNew.setObjectName(_fromUtf8("actionNew"))
self.actionExit = QtGui.QAction(MainWindow)
self.actionExit.setObjectName(_fromUtf8("actionExit"))
self.menuFile.addAction(self.actionNew)
self.menuFile.addAction(self.actionExit)
self.menubar.addAction(self.menuFile.menuAction())
#
self.Doc_1 = QtGui.QWidget()
self.Doc_1.setObjectName(_fromUtf8("Doc_1"))
self.gridLayout_2 = QtGui.QGridLayout(self.Doc_1)
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.textEdit = QtGui.QTextEdit(self.Doc_1)
self.textEdit.setMinimumSize(QtCore.QSize(100, 200))
self.textEdit.setMaximumSize(QtCore.QSize(741, 16777215))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.gridLayout_2.addWidget(self.textEdit, 0, 0, 1, 1)
#
self.retranslateUi(MainWindow)
QtCore.QObject.connect(self.actionExit, QtCore.SIGNAL(_fromUtf8("triggered()")), MainWindow.close)
QtCore.QObject.connect(self.actionNew, QtCore.SIGNAL(_fromUtf8("triggered()")), self.opennew)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def opennew(self):
self.mdiArea.addSubWindow(Doc_1);
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.Doc_1.setWindowTitle(_translate("MainWindow", "Doc_1", None))
self.menuFile.setTitle(_translate("MainWindow", "file", None))
self.actionNew.setText(_translate("MainWindow", "new", None))
self.actionNew.setShortcut(_translate("MainWindow", "Ctrl+N", None))
self.actionExit.setText(_translate("MainWindow", "exit", None))
self.actionExit.setShortcut(_translate("MainWindow", "Ctrl+X", None))
答案 0 :(得分:0)
你可以根据很多很酷的教程。
Here非常棒。一开始就给了我很多帮助。