PDA

View Full Version : Proper way to call custom dialogs



Richard12345
22nd July 2008, 07:51
Hi small problem here that holding me up, I am using PYQT4
I am trying to call a second window from my QMainWindow, but I keep getting AttributeError: exec_
This is a very basic example of what I am trying to do.
One mainwindow with a pushbutton designed with Qt Designer,
and a second dialog window with a couple of pushbuttons in it also designed in Qt Designer.
both windows are set to ApplicationModal,
I used pyuic4 to convert the .ui files to .py files,
When the pushbutton is pressed the local function 'hit' tries to load to second window.
Files are attached.
Any help appreciated.

Cheers Richard

My start.py looks like this,



import sys
import MySQLdb
from PyQt4 import QtCore, QtGui, QtSql
from main import Ui_MainWindow
from dialog import Ui_Dialog
from PyQt4.QtGui import *
from PyQt4.QtCore import *



class StartQT4(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.hit)

def hit(self):
print 'hit'
dia = QtGui.QWidget()
dia = dialog1()
dia.show()
dia.exec_()


class dialog1(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.di = Ui_Dialog()
self.di.setupUi(self)




if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
myapp = StartQT4()
myapp.show()
sys.exit(app.exec_())

wysota
22nd July 2008, 22:56
exec() is part of QDialog and not QWidget - your widget should derive from the former.

Richard12345
22nd July 2008, 23:34
Ah thank you, very much.
That did the trick.

Cheers Richard