[frameworks/kirigami] src: Work around missing support for QKeyShortcut in shortcut

Manuel Alcaraz Zambrano <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit af71085c817e404b2b23c875af3c587f800a99d0 by Manuel Alcaraz Zambrano.
Committed on 24/07/2026 at 16:36.
Pushed by manuelal into branch 'master'.

Work around missing support for QKeyShortcut in shortcut

The shortcut property supports a StandardKey and a string. When passing
a QKeyShortcut, it gets converted to a string, but the converter uses
the localized version of the shortcut, which normally does not work when
the language is other than English.

This won't be necessary once we can depend on Qt 6.11, when
https://codereview.qt-project.org/c/qt/qtdeclarative/+/751770 is
available.

M  +5    -0    src/actionhelper.cpp
M  +1    -0    src/actionhelper.h
M  +4    -1    src/controls/Action.qml

https://invent.kde.org/frameworks/kirigami/-/commit/af71085c817e404b2b23c875af3c587f800a99d0

diff --git a/src/actionhelper.cpp b/src/actionhelper.cpp
index c537298d7..64c5e792c 100644
--- a/src/actionhelper.cpp
+++ b/src/actionhelper.cpp
@@ -8,6 +8,11 @@ ActionHelper::ActionHelper(QObject *parent)
 {
 }
 
+QString ActionHelper::nativeKey(const QKeySequence &keys)
+{
+    return keys.toString();
+}
+
 QString ActionHelper::iconName(const QIcon &icon) const
 {
     return icon.name();
diff --git a/src/actionhelper.h b/src/actionhelper.h
index e993b2e97..d2e80ac8b 100644
--- a/src/actionhelper.h
+++ b/src/actionhelper.h
@@ -16,6 +16,7 @@ class ActionHelper : public QObject
 public:
     explicit ActionHelper(QObject *parent = nullptr);
 
+    Q_INVOKABLE QString nativeKey(const QKeySequence &keys);
     Q_INVOKABLE QList<QKeySequence> alternateShortcuts(QAction *action) const;
     Q_INVOKABLE QString iconName(const QIcon &icon) const;
 };
diff --git a/src/controls/Action.qml b/src/controls/Action.qml
index 1f5a1dedb..7d05b3c77 100644
--- a/src/controls/Action.qml
+++ b/src/controls/Action.qml
@@ -151,7 +151,10 @@ QQC2.Action {
     readonly property list<T.Action> visibleChildren: children
         .filter(action => !(action instanceof Action) || action.visible)
 
-    shortcut: fromQAction?.shortcut
+    // TODO: Remove workaround once we can depend on Qt 6.11. See https://codereview.qt-project.org/c/qt/qtdeclarative/+/751770
+    shortcut: if (fromQAction) {
+        return P.ActionHelper.nativeKey(fromQAction.shortcut);
+    }
     text: fromQAction?.text ?? ''
     icon.name: {
         if (!fromQAction) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.