diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2019-03-27 16:23:24 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-04-08 08:40:54 +0000 |
commit | 2431853d824c6416f2cb760485df5cb4c27db7e5 (patch) | |
tree | 11ec5624cf4e78cf1a218e8aa5c458326f354d5a | |
parent | bb4b463c93623635154749e200304d8210b88bda (diff) |
SpinBox: fix indicators being hovered when mouse is moved while pressed
We also need to update the hovered state of each indicator when
the mouse is moved while pressed, not just when we get hover move
events.
Change-Id: I6fa71344fd540f648683958e5804ae735523e72d
Fixes: QTBUG-74688
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickspinbox.cpp | 6 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_spinbox.qml | 33 |
2 files changed, 37 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickspinbox.cpp b/src/quicktemplates2/qquickspinbox.cpp index 6af1d8e8..274929b0 100644 --- a/src/quicktemplates2/qquickspinbox.cpp +++ b/src/quicktemplates2/qquickspinbox.cpp @@ -362,8 +362,10 @@ void QQuickSpinBoxPrivate::handleMove(const QPointF &point) QQuickControlPrivate::handleMove(point); QQuickItem *ui = up->indicator(); QQuickItem *di = down->indicator(); - up->setPressed(ui && ui->isEnabled() && ui->contains(ui->mapFromItem(q, point))); - down->setPressed(di && di->isEnabled() && di->contains(di->mapFromItem(q, point))); + up->setHovered(ui && ui->isEnabled() && ui->contains(ui->mapFromItem(q, point))); + up->setPressed(up->isHovered()); + down->setHovered(di && di->isEnabled() && di->contains(di->mapFromItem(q, point))); + down->setPressed(down->isHovered()); bool pressed = up->isPressed() || down->isPressed(); q->setAccessibleProperty("pressed", pressed); diff --git a/tests/auto/controls/data/tst_spinbox.qml b/tests/auto/controls/data/tst_spinbox.qml index 419478a2..d3a0d8bb 100644 --- a/tests/auto/controls/data/tst_spinbox.qml +++ b/tests/auto/controls/data/tst_spinbox.qml @@ -486,6 +486,39 @@ TestCase { compare(button.hovered, false) } + function test_hoverWhilePressed_data() { + return [ + { tag: "up" }, + { tag: "down" }, + ] + } + + // QTBUG-74688 + function test_hoverWhilePressed(data) { + var control = createTemporaryObject(spinBox, testCase, { hoverEnabled: true, value: 50 }) + verify(control) + + var button = control[data.tag] + compare(control.hovered, false) + compare(button.hovered, false) + + // Hover over the indicator. It should be hovered. + var buttonXCenter = button.indicator.x + button.indicator.width / 2 + var buttonYCenter = button.indicator.y + button.indicator.height / 2 + mouseMove(control, buttonXCenter, buttonYCenter) + compare(button.hovered, true) + + // Press on the indicator and then move the mouse outside of it. + mousePress(control, buttonXCenter, buttonYCenter) + compare(button.hovered, true) + mouseMove(control, buttonXCenter - button.indicator.width, buttonYCenter - button.indicator.height) + // It should not be pressed or hovered. + compare(button.pressed, false) + compare(button.hovered, false) + + mouseRelease(control) + } + function test_valueFromText_data() { return [ { tag: "editable", editable: true }, |