Add keyboard/gamepad focus navigation to dialog buttons

This commit is contained in:
Cameron Gutman
2026-01-27 00:13:47 -06:00
parent 6d40c61850
commit d040bd24d1

View File

@@ -15,7 +15,9 @@ NavigableDialog {
onOpened: { onOpened: {
// Force keyboard focus on the label so keyboard navigation works // Force keyboard focus on the label so keyboard navigation works
dialogLabel.forceActiveFocus() if (dialogButtonBox.count > 0) {
dialogButtonBox.itemAt(dialogButtonBox.count - 1).forceActiveFocus(Qt.TabFocus)
}
} }
RowLayout { RowLayout {
@@ -52,18 +54,6 @@ NavigableDialog {
// will cause word wrap to kick in. // will cause word wrap to kick in.
Layout.maximumWidth: 400 Layout.maximumWidth: 400
Layout.maximumHeight: 400 Layout.maximumHeight: 400
Keys.onReturnPressed: {
accept()
}
Keys.onEnterPressed: {
accept()
}
Keys.onEscapePressed: {
reject()
}
} }
} }
@@ -71,6 +61,15 @@ NavigableDialog {
id: dialogButtonBox id: dialogButtonBox
standardButtons: dialog.standardButtons standardButtons: dialog.standardButtons
delegate: Button {
flat: true
Keys.onReturnPressed: clicked()
Keys.onEnterPressed: clicked()
Keys.onRightPressed: nextItemInFocusChain(true).forceActiveFocus(Qt.TabFocus)
Keys.onLeftPressed: nextItemInFocusChain(false).forceActiveFocus(Qt.TabFocus)
}
onHelpRequested: { onHelpRequested: {
Qt.openUrlExternally(helpUrl) Qt.openUrlExternally(helpUrl)
close() close()