PDA

View Full Version : QMainWindow how to know when focus lost?



arkaha
11th February 2010, 22:21
Hi everybody! i'm trying to write a program on a pyqt4, on my ubuntu.
I have QMainWindow with text field and button on it, and i need to know when the user stops working with my window, and switches to other(not mine) window, i've tryed to use focusOutEvent for QMainWindow but it does not work, please tell me what im doing wrong.


class TranslateView(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
def focusOutEvent(self, event):
print "out"

thanks in advance, and sorry for my english.

franz
12th February 2010, 06:26
From the documentation (http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qwidget.html#focusOutEvent):

A widget normally must setFocusPolicy() to something other than Qt.NoFocus in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)