diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-05-16 15:51:40 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-05-30 13:34:36 +0000 |
commit | eaa2b5d59cdcd899f540996520c64fad677b429e (patch) | |
tree | a6d16154fe65feb0a5a4a60cf887c3c82d3c0836 /tests | |
parent | f289313f109f474c90e72c20d01eb7c8c421f6d2 (diff) |
QQuickComboBox: update highlighted index on mouse hover
This is the expected behavior on desktop.
NOTE: We can no longer rely on ListView.ApplyRange, because if ListView
adjusts the content position while key navigating or scrolling, "wrong"
items may get hovered and the highlighted index gets set incorrectly
leading to a hovered->highlight->hovered loop. Therefore we force
ListView.NoHighlightRange to keep existing styles working without
modifications.
Change-Id: I57fe3de1230dd6348d01c1785cd09d4fb184d28a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 3d8777b3..39a1d145 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -699,7 +699,7 @@ TestCase { compare(highlightedSpy.count, 0) mouseMove(content, content.width / 2 + 1, content.height / 2 + 1) compare(activatedSpy.count, 0) - compare(highlightedSpy.count, 0) + compare(highlightedSpy.count, 1) mouseRelease(content) compare(activatedSpy.count, 1) compare(highlightedSpy.count, 1) @@ -1143,6 +1143,55 @@ TestCase { closedSpy.target = null } + function test_mouseHighlight() { + var control = createTemporaryObject(comboBox, testCase, {model: 20}) + verify(control) + + compare(control.highlightedIndex, -1) + + var openedSpy = signalSpy.createObject(control, {target: control.popup, signalName: "opened"}) + verify(openedSpy.valid) + + control.popup.open() + compare(control.highlightedIndex, 0) + tryCompare(openedSpy, "count", 1) + + var listview = control.popup.contentItem + verify(listview) + waitForRendering(listview) + + // hover-highlight through all visible list items one by one + var hoverIndex = -1 + var prevHoverItem = null + for (var y = 0; y < listview.height; ++y) { + var hoverItem = listview.itemAt(0, listview.contentY + y) + if (!hoverItem || !hoverItem.visible || hoverItem === prevHoverItem) + continue + mouseMove(hoverItem, 0, 0) + tryCompare(control, "highlightedIndex", ++hoverIndex) + prevHoverItem = hoverItem + } + + mouseMove(listview, listview.width / 2, listview.height / 2) + + // wheel-highlight the rest of the items + var delta = 120 + var prevWheelItem = null + while (!listview.atYEnd) { + var prevContentY = listview.contentY + mouseWheel(listview, listview.width / 2, listview.height / 2, -delta, -delta) + tryCompare(listview, "moving", false) + verify(listview.contentY > prevContentY) + + var wheelItem = listview.itemAt(listview.width / 2, listview.contentY + listview.height / 2) + if (!wheelItem || !wheelItem.visible || wheelItem === prevWheelItem) + continue + + tryCompare(control, "highlightedIndex", parseInt(wheelItem.text)) + prevWheelItem = wheelItem + } + } + RegExpValidator { id: regExpValidator regExp: /(red|blue|green)?/ |