[PyQt] FocusEvent problem with QTabWidget

Philippe Fremy phil at freehackers.org
Tue Mar 10 16:45:22 GMT 2009


Hi,

I am trying to catch focus events on my main widget, which happens to be
a QTabWidget. It does not work if the widget is a QTabWidget but works
for a regular QWidget. See the attached program, where you can choose
the base class.

I don't think I'm doing something wrong, so it's either a PyQt bug or Qt
bug.

Any confirmation ?

cheers,

Philippe
-------------- next part --------------

from PyQt4 import QtGui, QtCore

# parentClass = QtGui.QWidget 
# parentClass = QtGui.QTabWidget
parentClass = QtGui.QTextEdit

class MyWidget( parentClass ):
	def __init__(self, *args ):
		parentClass.__init__( self, *args )
		print 'old focus policy: ', self.focusPolicy()
		self.setFocusPolicy( QtCore.Qt.TabFocus )
		print 'new focus policy: ', self.focusPolicy()

	def focusInEvent( self, focusEvent ):
		print 'focusInEvent'
		parentClass.focusInEvent( self, focusEvent )

	def focusOutEvent( self, focusEvent ):
		print 'focusOutEvent'
		parentClass.focusInEvent( self, focusEvent )

		

def main():
    app = QtGui.QApplication([])
    w = MyWidget()
    w.setFocus()
    w.show()
    app.exec_()

if __name__ == '__main__':
    main()



More information about the PyQt mailing list