diff options
author | ronso0 <ronso0@mixxx.org> | 2020-02-02 17:18:14 +0100 |
---|---|---|
committer | ronso0 <ronso0@mixxx.org> | 2020-02-02 17:18:14 +0100 |
commit | 8beb1dfc2580044c45e3c98e20751c12afbb5ca7 (patch) | |
tree | c0195d46ce942ded4ca978f47d012b758b2fcec3 /src/widget | |
parent | 9f61e15ebb203a3d88eb94e80782cfcc952710c1 (diff) |
WPushButton: override hover property to also repaint its text label
Diffstat (limited to 'src/widget')
-rw-r--r-- | src/widget/wpushbutton.cpp | 15 | ||||
-rw-r--r-- | src/widget/wpushbutton.h | 13 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 613b4bbe51..0b6ef0bc22 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -70,7 +70,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { } } - // Load pixmaps for associated states + // Load pixmaps and set texts for associated states QDomNode state = context.selectNode(node, "State"); while (!state.isNull()) { if (state.isElement() && state.nodeName() == "State") { @@ -227,6 +227,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { } void WPushButton::setStates(int iStates) { + m_bHovered = false; m_bPressed = false; m_iNoStates = iStates; m_activeTouchButton = Qt::NoButton; @@ -341,6 +342,18 @@ void WPushButton::paintEvent(QPaintEvent* e) { } } +void WPushButton::enterEvent(QEvent *event) { + m_bHovered = true; + restyleAndRepaint(); + return QWidget::enterEvent(event); +} + +void WPushButton::leaveEvent(QEvent *event) { + m_bHovered = false; + restyleAndRepaint(); + return QWidget::leaveEvent(event); +} + void WPushButton::mousePressEvent(QMouseEvent * e) { const bool leftClick = e->button() == Qt::LeftButton; const bool rightClick = e->button() == Qt::RightButton; diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index f622e3be7d..f736fd5b41 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -48,6 +48,15 @@ class WPushButton : public WWidget { return m_bPressed; } + // #MyPushButton:hover would affect most object styles except font color + // so we use a custom property that allows to also change the font color + // with #MyPushButton[hover="true"] {} + Q_PROPERTY(bool hover READ isHovered); + + bool isHovered() const { + return m_bHovered; + } + // The displayValue property is used to restyle the pushbutton with CSS. // The declaration #MyButton[displayValue="0"] { } will define the style // when the widget is in state 0. This allows for effects like reversing @@ -78,6 +87,8 @@ class WPushButton : public WWidget { void paintEvent(QPaintEvent* /*unused*/) override; void mousePressEvent(QMouseEvent* e) override; void mouseReleaseEvent(QMouseEvent* e) override; + void enterEvent(QEvent *event) override; + void leaveEvent(QEvent *event) override; void focusOutEvent(QFocusEvent* e) override; void fillDebugTooltip(QStringList* debug) override; @@ -97,6 +108,8 @@ class WPushButton : public WWidget { // True, if the button is currently pressed bool m_bPressed; + // True, if the button is pointer is above button + bool m_bHovered; // Array of associated pixmaps int m_iNoStates; |