Only set initial MenuItem focus if not activating via mouse
Having an initially highlighted item when using mouse navigation doesn't adhere to UX norms and also can lead to a janky feeling when the focus flip-flops from the item under the user's cursor to the first item as the Menu opens.
This commit is contained in:
parent
b4a5d21f97
commit
6d40c61850
3 changed files with 13 additions and 6 deletions
|
|
@ -288,6 +288,7 @@ CenteredGridView {
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
sourceComponent: NavigableMenu {
|
sourceComponent: NavigableMenu {
|
||||||
id: appContextMenu
|
id: appContextMenu
|
||||||
|
initiator: appContextMenuLoader.parent
|
||||||
NavigableMenuItem {
|
NavigableMenuItem {
|
||||||
text: model.running ? qsTr("Resume Game") : qsTr("Launch Game")
|
text: model.running ? qsTr("Resume Game") : qsTr("Launch Game")
|
||||||
onTriggered: launchOrResumeSelectedApp(true)
|
onTriggered: launchOrResumeSelectedApp(true)
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,18 @@ import QtQuick 2.0
|
||||||
import QtQuick.Controls 2.2
|
import QtQuick.Controls 2.2
|
||||||
|
|
||||||
Menu {
|
Menu {
|
||||||
|
property var initiator
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
// Give focus to the first visible and enabled menu item
|
// If the initiating object currently has keyboard focus,
|
||||||
for (var i = 0; i < count; i++) {
|
// give focus to the first visible and enabled menu item
|
||||||
var item = itemAt(i)
|
if (initiator.focus) {
|
||||||
if (item.visible && item.enabled) {
|
for (var i = 0; i < count; i++) {
|
||||||
item.forceActiveFocus(Qt.TabFocusReason)
|
var item = itemAt(i)
|
||||||
break
|
if (item.visible && item.enabled) {
|
||||||
|
item.forceActiveFocus(Qt.TabFocusReason)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,7 @@ CenteredGridView {
|
||||||
asynchronous: true
|
asynchronous: true
|
||||||
sourceComponent: NavigableMenu {
|
sourceComponent: NavigableMenu {
|
||||||
id: pcContextMenu
|
id: pcContextMenu
|
||||||
|
initiator: pcContextMenuLoader.parent
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("PC Status: %1").arg(model.online ? qsTr("Online") : qsTr("Offline"))
|
text: qsTr("PC Status: %1").arg(model.online ? qsTr("Online") : qsTr("Offline"))
|
||||||
font.bold: true
|
font.bold: true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue