2

I need to open some dialogs in my MainWidget application. When I call exec_() function dialog window appears but has nothing. I cannot even set up the title. Here some example of problem:

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_())

If I call the same code for dialog from dialog widget it works. Thanks for help!

1 Answer 1

2

Your problem is typo. You typed the overriden constructor of class prceditor with only one underscore after init instead of two underscores. The overriden version was never executed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.