summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp1
-rw-r--r--src/widgets/widgets/qpushbutton.cpp14
-rw-r--r--src/widgets/widgets/qpushbutton_p.h5
3 files changed, 19 insertions, 1 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 14bca7fbe4..ae5d14ab9c 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -2848,6 +2848,7 @@ void QStyleSheetStyle::polish(QWidget *w)
if ( cssClass & PseudoClass_Hover || negated & PseudoClass_Hover) {
w->setAttribute(Qt::WA_Hover);
embeddedWidget(w)->setAttribute(Qt::WA_Hover);
+ embeddedWidget(w)->setMouseTracking(true);
}
}
diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp
index 3d075bf92f..d182d7d33d 100644
--- a/src/widgets/widgets/qpushbutton.cpp
+++ b/src/widgets/widgets/qpushbutton.cpp
@@ -332,6 +332,8 @@ void QPushButton::initStyleOption(QStyleOptionButton *option) const
option->state |= QStyle::State_On;
if (!d->flat && !d->down)
option->state |= QStyle::State_Raised;
+ if (underMouse() && hasMouseTracking())
+ option->state.setFlag(QStyle::State_MouseOver, d->hovering);
option->text = d->text;
option->icon = d->icon;
option->iconSize = iconSize();
@@ -691,6 +693,18 @@ bool QPushButton::event(QEvent *e)
updateGeometry();
} else if (e->type() == QEvent::PolishRequest) {
updateGeometry();
+ } else if (e->type() == QEvent::MouseMove) {
+ const QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(e);
+ if (testAttribute(Qt::WA_Hover)) {
+ bool hit = false;
+ if (underMouse())
+ hit = hitButton(mouseEvent->pos());
+
+ if (hit != d->hovering) {
+ update(rect());
+ d->hovering = hit;
+ }
+ }
}
return QAbstractButton::event(e);
}
diff --git a/src/widgets/widgets/qpushbutton_p.h b/src/widgets/widgets/qpushbutton_p.h
index 439b6e35d6..7a5458ea3b 100644
--- a/src/widgets/widgets/qpushbutton_p.h
+++ b/src/widgets/widgets/qpushbutton_p.h
@@ -69,7 +69,9 @@ public:
QPushButtonPrivate()
: QAbstractButtonPrivate(QSizePolicy::PushButton), autoDefault(Auto),
- defaultButton(false), flat(false), menuOpen(false), lastAutoDefault(false) {}
+ defaultButton(false), flat(false), menuOpen(false), hovering(false),
+ lastAutoDefault(false)
+ {}
inline void init() { resetLayoutItemMargins(); }
static QPushButtonPrivate* get(QPushButton *b) { return b->d_func(); }
@@ -89,6 +91,7 @@ public:
uint defaultButton : 1;
uint flat : 1;
uint menuOpen : 1;
+ uint hovering : 1;
mutable uint lastAutoDefault : 1;
};