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
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()

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to