PDA

View Full Version : focusChanged() not working for me.



GGibson
5th December 2008, 10:04
Hi, maybe you can tell me what I'm doing wrong. Using Qt4 PyQt. I get no errors but my slot/handler never fires.

Thanks for looking - this is driving me nuts.


#MainApplication.py
from PyQt4.QtGui import QApplication
from PyQt4 import QtCore

class Application(QApplication):

def __init__(self, *args):
QApplication.__init__(self, *args)

def setupSignals(self):
print "setting up signals..."
QtCore.QObject.connect(self, QtCore.SIGNAL("focusChanged()"), self.changedFocusSlot)

def changedFocusSlot(self, old, now):
print "focus changed"

#main.py
#!/usr/bin/python

from mainWindowUI import MainWindow
from PyQt4 import QtGui, QtCore
import sys
from MainApplication import Application

def main():
app = Application(sys.argv)
wnd = MainWindow()
wnd.show()
wnd.activateWindow()
app.setupSignals()
sys.exit(app.exec_())

if __name__ == '__main__':
main()

munna
5th December 2008, 10:22
I am not too familiar with Python or PyQt but I think the problem is with your QObject.connect line.

The SIGNAL is focusChanged with no parameters but the slot takes 2 parameter. I think the signal should be something like


QtCore.SIGNAL("focusChanged(QWidget *, QWidget *)")

Hope this helps

GGibson
5th December 2008, 16:07
Yay! That works.

Thought I already tried that and every variation *forehead slap*.

Thanks a bunch.