unfortunately I am pretty new to Python and Qt and all that. Well, I managed to successfully program a little stuff for my work (computational neuroscientist... no comment please), using a simple graphical interface and binding it to my long existing C library. There was no problem, everything was running fine...
... until I decided to upgrade everything to kubuntu's Edgy and PyQt4. Well, I understood that I need to port my original PyQt3 stuff, as there are many principle changes in PyQt4. Anyway, I created my interfaces with Qt4 builder from Trolltech, and connected the buttons in my main Python program (that's the normal way to do, I guess?) However, this most basic "connect" does not work anymore, and I am to new to all that to understand why. Here is an example code which explains the problem:
First, the python code for the ui, generated with pyuic4:
Expand|Select|Wrap|Line Numbers
- import sys
- from PyQt4 import QtCore, QtGui
- class Ui_Dialog(object):
- def setupUi(self, Dialog):
- Dialog.setObjectName("Dialog")
- Dialog.resize(QtCore.QSize(QtCore.QRect(0,0,400,300).size()).expandedTo(Dialog.minimumSizeHint()))
- self.buttonBox = QtGui.QDialogButtonBox(Dialog)
- self.buttonBox.setGeometry(QtCore.QRect(30,240,341,32))
- self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
- self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.NoButton|QtGui.QDialogButtonBox.Ok)
- self.buttonBox.setObjectName("buttonBox")
- self.okButton = QtGui.QPushButton(Dialog)
- self.okButton.setGeometry(QtCore.QRect(70,70,80,27))
- self.okButton.setObjectName("okButton")
- self.retranslateUi(Dialog)
- QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("accepted()"),Dialog.accept)
- QtCore.QObject.connect(self.buttonBox,QtCore.SIGNAL("rejected()"),Dialog.reject)
- #QtCore.QObject.connect(self.okButton,QtCore.SIGNAL("clicked()"),self.bok0)
- QtCore.QMetaObject.connectSlotsByName(Dialog)
- #def bok0(self):
- #print "OK !!!!!!!!"
- def retranslateUi(self, Dialog):
- Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
- self.okButton.setText(QtGui.QApplication.translate("Dialog", "New OK", None, QtGui.QApplication.UnicodeUTF8))
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/env python
- import sys
- from PyQt4 import QtCore, QtGui
- from untitled import Ui_Dialog
- class TestDialog(QtGui.QDialog, Ui_Dialog):
- def __init__(self):
- QtGui.QDialog.__init__(self)
- # Set up the user interface from Designer.
- self.setupUi(self)
- # Connect up the buttons.
- self.connect(self.okButton, QtCore.SIGNAL("clicked"), self.bok)
- @QtCore.pyqtSignature("")
- def bok(self):
- print "OK 2 !!!!!!!!"
- if __name__ == '__main__':
- app = QtGui.QApplication(sys.argv)
- window = QtGui.QDialog()
- ui = TestDialog()
- ui.setupUi(window)
- window.show()
- sys.exit(app.exec_())
I would very much appreciate if there is somebody who could help me in this matter. Please feel free to tell me that I am stupid as I made a stupid mistake... no hard feelings ;-)
Cheers,
Michelle
- a.k.a. Angel of Darkness -