I have a PyQt4 program where I'm trying to get notified when a window gets focus, following the advice in the QUndoGroup docs:
It is the programmer's responsibility to specify which stack is active by calling QUndoStack::setActive(), usually when the associated document window receives focus.
But I have a weird problem where only one window actually gets the focusIn and focusOut events, while the others either receive only one at their creation, or else never receive them at all. Here is an example program:
#!/usr/bin/env python
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.label = QLabel('Window')
self.setCentralWidget(self.label)
self.setFocusPolicy(Qt.StrongFocus)
def focusInEvent(self, event):
self.label.setText('Got focus')
def focusOutEvent(self, event):
self.label.setText('Lost focus')
def main():
app = QApplication(sys.argv)
win1 = MyWindow()
win2 = MyWindow()
win1.show()
win2.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()