Reputation: 1
I have a PyQt application with stylesheet formatted widgets. The buttons have a css change (clicked) function on them, like this:
CSS
But I would like to achieve this:
animated
Is there a way to animate stylesheet as mentioned above, or I have to manipulate the button's paint event, or something else? Could you give some help, please?!
Upvotes: 0
Views: 3276
Reputation: 730
You might need to have something like this...
from PyQt4 import QtGui
import sys
from PyQt4.QtCore import QSize
class PB(QtGui.QPushButton):
def __init__(self, *args, **kwargs):
QtGui.QPushButton.__init__(self, *args, **kwargs)
self.setMouseTracking(True)
def mouseMoveEvent(self, event):
if event.pos().x()>self.width()-10 or event.pos().y()>self.height()-10\
or event.pos().x() < 10 or event.pos().y()< 10:
bmp = QtGui.QIcon('/tmp/1.png')
self.setIcon(bmp)
else:
bmp = QtGui.QIcon('/tmp/2.png')
self.setIcon(bmp)
self.setIconSize(QSize(200,200))
return QtGui.QPushButton.mouseMoveEvent(self, event)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
w = QtGui.QWidget()
b = PB()
b.setParent(w)
b.setGeometry(50,50,200,200)
w.resize(300,300)
w.show()
sys.exit(app.exec_())
Attached images used.
Upvotes: 2