[PyQt] Changing the opacity of a frame when it doesn't have the focus

projetmbc projetmbc at club-internet.fr
Fri Apr 10 11:33:20 BST 2009


Hello,
I would like to catch the events when my frame has the focus or losts 
it. I don't understand why the following code doesn't work. Indeed, I 
would like the frame to have a 0.5 opacity when the focus is out and 1.0 
when it is in the frame.

Every tip or clue is welcome.
Christophe.

==========
 THE CODE
==========

class MyFrame(QtGui.QFrame):
    def __init__(self, parent, titre, pixmapfile):
        QtGui.QFrame.__init__(self, parent, QtCore.Qt.Tool)
        self.setWindowTitle(titre)
        rect = QtCore.QRect(QtGui.QCursor.pos(), pixmapfile.size())
        self.setGeometry(rect)
        self.setFixedSize(pixmapfile.size())

        label = QtGui.QLabel(self)
        label.setPixmap(pixmapfile)
        label.show()

        self.timer = QtCore.QTimer()
       
        self.connect( self.timer, QtCore.SIGNAL("timeout()"), self, 
QtCore.SLOT("hide()"))

    def focusOutEvent(self, evt):
        print 'out'
   
    def focusInEvent(self, evt):
        print 'in'

    def showEvent(self, evt):
        self.timer.start(10000) # 10 seconds
        QtGui.QFrame.showEvent(self, evt)



More information about the PyQt mailing list