PDA

View Full Version : PyQt... What am I doing wrong?!



Richie
1st September 2009, 23:06
Hi guys, just starting out with Qt using PyQt, and not having a great time! Anyone help me out here... I'm trying to get a button to print "hello world". Stereotypical and unimaginative, I know, but hey, you have to start somewhere! Problem is, I click it and nothing happens! It's not even calling the function. I think my connect statement is rubbish. Can you help?

Ta,

Rich

from PyQt4 import QtCore, QtGui


class Ui_About(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(388, 336)
self.btnOK = QtGui.QPushButton(Dialog)
self.btnOK.setGeometry(QtCore.QRect(130, 300, 110, 23))
self.btnOK.setObjectName("btnOK")

QtCore.QObject.connect(self.btnOK, QtCore.SIGNAL("clicked()"), self.hello)
QtCore.QMetaObject.connectSlotsByName(Dialog)

def hello(self):
print "hello world"

wysota
2nd September 2009, 08:30
Ui_about is not a QObject, it can't have slots. If you modified the code generated by pyuic then don't do it. You should provide your own subclass of QWidget and place the slot there. Consult the docs for using Designer generated components in your application.

Richie
4th September 2009, 17:14
Much appreciated, got it all working now, many thanks.