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_())
如果我从对话框小部件为对话框调用相同的代码,它将起作用。感谢帮助!
没有找到相关结果
已邀请:
1 个回复
钨蜡唤喉晤