Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.2.0, 5.5.0 Beta, 5.8, 5.10.0 Beta 1, 5.10.0, 5.9, 5.10.1, 5.15.2, 6.2.0 FF
-
Any
Description
It is difficult to handle cases where you are limited to keyboard navigation only, and use KeyNavigation to move between items inside focus scopes.
If an item with active focus is disabled, focus will remain on this item in the focus scope. Keyboard navigation is then stuck there.
Below is some example code to try to explain this further. It can be copy/pasted directly into a blank qmlproject.
It would make life easier if the focus scope would move active focus to the next child item with activeFocusOnTab and enabled both set to true.
If no items were found, it could do something like emulate pushing the "tab" key which would move focus on to the next item in the tab chain (thereby moving focus away from itself).
Unable to find source-code formatter for language: qml. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
import QtQuick 2.2 import QtQuick.Layouts 1.1 Rectangle { width: 800 height: 480 Keys.onPressed: { event.accepted = true; switch(event.key) { case Qt.Key_1: box1.enabled = !box1.enabled; return; case Qt.Key_2: box2.enabled = !box2.enabled; return; case Qt.Key_3: box3.enabled = !box3.enabled; return; case Qt.Key_4: box4.enabled = !box4.enabled; return; } event.accepted = false; } Text { anchors.centerIn: parent width: 300 height: 480 horizontalAlignment: Text.AlignLeft verticalAlignment: Text.AlignVCenter wrapMode: Text.Wrap text: "Use cursor keys to move focus around. Active focus is indicated with green. Focus indicated with red border. Disabled is indicated with grey. Use keys 1,2,3,4 to toggle the enabled property on the left boxes. Try having active focus on box1, then disable it. It becomes inpossible to use the up/down cursor keys to move to the next items in that column. You can use the right cursor to move to the right column, but if you move back, you still cannot reach the other boxes on the left. Also try having focus on box1, then go right. Disable box 1, and try to go back left. Active focus will go only to the focus scope behind the buttons. " } Rectangle { anchors.fill: leftColumn color: leftColumn.activeFocus ? "green" : "transparent" border.color: "red" border.width: leftColumn.focus ? 2 : 0 } FocusScope { id: leftColumn anchors.left: parent.left anchors.top: parent.top anchors.bottom: parent.bottom width: 200 focus: true ColumnLayout { anchors.fill: parent Rectangle { focus: true id: box1 color: enabled ? (activeFocus ? "green" : "orange") : (activeFocus ? "blue" : "gray") border.color: "red" border.width: focus ? 2 : 0 width: 180 height: 30 Text { anchors.fill: parent text: "box1" } KeyNavigation.down: box2 KeyNavigation.right: rightColumn activeFocusOnTab: true } Rectangle { focus: true id: box2 color: enabled ? (activeFocus ? "green" : "orange") : (activeFocus ? "blue" : "gray") border.color: "red" border.width: focus ? 2 : 0 width: 180 height: 30 Text { anchors.fill: parent text: "box2" } KeyNavigation.down: box3 KeyNavigation.right: rightColumn activeFocusOnTab: true } Rectangle { focus: true id: box3 color: enabled ? (activeFocus ? "green" : "orange") : (activeFocus ? "blue" : "gray") border.color: "red" border.width: focus ? 2 : 0 width: 180 height: 30 Text { anchors.fill: parent text: "box3" } KeyNavigation.down: box4 KeyNavigation.right: rightColumn activeFocusOnTab: true } Rectangle { focus: true id: box4 color: enabled ? (activeFocus ? "green" : "orange") : (activeFocus ? "blue" : "gray") border.color: "red" border.width: focus ? 2 : 0 width: 180 height: 30 Text { anchors.fill: parent text: "box4" } KeyNavigation.down: box1 KeyNavigation.right: rbox1 activeFocusOnTab: true } } } Rectangle { anchors.fill: rightColumn color: rightColumn.activeFocus ? "green" : "transparent" border.color: "red" border.width: rightColumn.focus ? 2 : 0 } FocusScope { id: rightColumn anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom width: 200 ColumnLayout { anchors.fill: parent Rectangle { focus: true id: rbox1 color: enabled ? (activeFocus ? "green" : "orange") : "gray" border.color: "red" border.width: focus ? 2 : 0 width: 180 height: 30 Text { anchors.fill: parent text: "rightbox1" } KeyNavigation.down: rbox2 KeyNavigation.left: leftColumn activeFocusOnTab: true } Rectangle { focus: true id: rbox2 color: enabled ? (activeFocus ? "green" : "orange") : "gray" border.color: "red" border.width: focus ? 2 : 0 width: 180 height: 30 Text { anchors.fill: parent text: "rightbox2" } KeyNavigation.down: rbox1 KeyNavigation.left: leftColumn activeFocusOnTab: true } } } }
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-35051 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
439667,1 | WIP Teach KeyNavigation to find another focus when its Item is disabled | dev | qt/qtdeclarative | Status: NEW | -2 | 0 |