2
我需要在我的MainWidget應用程序中打開一些對話框。當我調用exec_()函數時,會出現對話窗口,但什麼也沒有。我甚至不能設置標題。問題這裏是一些例子:PyQT調用QDialog窗體QMainWidget
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_())
如果我把相同的代碼從它的工作原理對話框控件對話框。感謝幫助!