PyQT通过QMainWidget调用QDialog

| 我需要在MainWidget应用程序中打开一些对话框。当我调用exec_()函数时,对话框窗口出现,但没有任何显示。我什至无法设置标题。这里有一些问题的例子:
import sys
from PyQt4 import QtGui, QtCore


class prceditor(QtGui.QDialog):
    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)
        self.setWindowTitle(\'PRC Editor\')
        self.resize(100,100)

class Glmainwnd(QtGui.QMainWindow):
    def __init__(self):
        super(Glmainwnd, self).__init__()
        # Resize Window
        screen = QtGui.QDesktopWidget().screenGeometry()
        self.resize(screen.width()/2, screen.height()/2)
        size = self.geometry()
        self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2)
        self.setWindowTitle(\'uniPRCsim\')
        self.setWindowIcon(QtGui.QIcon(\'icons/uniPRCsim.png\'))
        self.statusBar().showMessage(\'Ready\')

        menubar = self.menuBar()

        #Exit from APP
        exit = QtGui.QAction(QtGui.QIcon(\'icons/exit.png\'), \'Exit\', self)
        exit.setShortcut(\'Ctrl+Q\')
        exit.setStatusTip(\'Exit application\')
        self.connect(exit, QtCore.SIGNAL(\'triggered()\'), QtCore.SLOT(\'close()\'))
        dlg = QtGui.QAction(QtGui.QIcon(\'icons/exit.png\'), \'DLG\', self)
        dlg.setShortcut(\'Ctrl+D\')
        dlg.setStatusTip(\'Call Dlg\')
        self.connect(dlg, QtCore.SIGNAL(\'triggered()\'), self.mdlg)

        file = menubar.addMenu(\'&File\')
        file.addAction(dlg)
        file.addSeparator()
        file.addAction(exit)

    def mdlg(self):
        p=prceditor(self)
        p.exec_()


if __name__ == \'__main__\' :
    app = QtGui.QApplication(sys.argv)
    main = Glmainwnd()
    main.show()
    sys.exit(app.exec_())
如果我从对话框小部件为对话框调用相同的代码,它将起作用。感谢帮助!     
已邀请:
你的问题是错字。您在初始化后只键入了一个下划线而不是两个下划线,从而键入了prceditor类的重写构造函数。覆盖的版本从未执行。     

要回复问题请先登录注册