Reputation: 1
I want to have a push button in Qt C++ which changes color while hovered.
I have tried creating a custom class from QPushButton and overriding enterEvent
and leaveEvent
methods as below, but it didn't have an effect on the color.
class ColorChangingButtom : public QPushButton{
public:
ColorChangingButtom(QWidget *parent = nullptr) : QPushButton(parent){
setStyleSheet("QPushButtom {background-color:blue; color white;}");
}
protected:
void enterEvent(QMouseEvent *event) {
QPushButton::mouseMoveEvent(event);
setStyleSheet("QPushButtom {background-color:red; color white;}");
}
void leaveEvent(QEvent *event) override{
QPushButton::leaveEvent(event);
setStyleSheet("QPushButtom {background-color:blue; color white;}");
}
};
Upvotes: 0
Views: 71