I am tired of searching !
i subclassed a Button from QPushbutton and set my QSS to it.the style is desired.
all i want is when the button is hover (enterevent happen) the button's color change over a specific time (for example 0.2 sec) not immediately (a soft color changing)
what should i do ?
*******Answer in PyQt4*********
class MyButton(QPushButton):
def __init__(self):
super(MyButton, self).__init__()
self.setMinimumSize(80,50)
self.setText('QPushButton')
def getColor(self):
return Qt.black
def setColor(self, color):
self.setStyleSheet("background-color: rgb({0}, {1}, {2});border:none;".format(color.red(), color.green(), color.blue()))
color=QtCore.pyqtProperty(QColor, getColor, setColor)
def enterEvent(self, event):
global anim
anim=QPropertyAnimation(self, "color")
anim.setDuration(200)
anim.setStartValue(QColor(216, 140, 230))
anim.setEndValue(QColor(230, 230, 230))
anim.start()
def leaveEvent(self, event):
self.setStyleSheet("background:none;")