vcl/qt5/QtInstanceMenu.cxx |   18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

New commits:
commit d7dc43d5860ceef17f80e1d0e0faf2a67a59a94f
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Feb 6 23:21:45 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Feb 7 06:34:02 2026 +0100

    tdf#130857 qt weld: Support radio menu items in QtInstanceMenu::insert
    
    Setting the action to checkable and adding it into
    a QActionGroup results in it being displayed with
    a radio button.
    
    For Qt, all mutually exclusive actions/menu entries would usually be put
    into the same QActionGroup. However, LO currently manually implements
    logic to toggle all other entries off when one gets enabled and doesn't
    use the concept of groups.  Creating a separate QActionGroup for each
    item causes each item to be displayed with a radio button and leaves
    control for manually toggling on/off, so go with that approach for now.
    
    This will be used e.g. by the menu button in the
    sidebar, whose menu allows to switch between the different
    sidebar decks.
    
    (Use of native widgets isn't enabled for the sidebar
    yet, but this is one step, and in a WIP branch,
    radio buttons are displayed as expected with this
    change in place.)
    
    Change-Id: I07f779908710773b53cd565bf252636503049388
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198875
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/vcl/qt5/QtInstanceMenu.cxx b/vcl/qt5/QtInstanceMenu.cxx
index 5d580c4905e0..d4a76085ab71 100644
--- a/vcl/qt5/QtInstanceMenu.cxx
+++ b/vcl/qt5/QtInstanceMenu.cxx
@@ -20,8 +20,10 @@
 #include <vcl/qt/QtUtils.hxx>
 
 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+#include <QtGui/QActionGroup>
 #include <QtGui/QShortcut>
 #else
+#include <QtWidgets/QActionGroup>
 #include <QtWidgets/QShortcut>
 #endif
 
@@ -152,9 +154,6 @@ void QtInstanceMenu::insert(int nPos, const OUString& rId, 
const OUString& rStr,
                             const css::uno::Reference<css::graphic::XGraphic>& 
rImage,
                             TriState eCheckRadioFalse)
 {
-    assert(eCheckRadioFalse != TRISTATE_FALSE
-           && "Support for radio menu items not implemented yet");
-
     SolarMutexGuard g;
 
     GetQtInstance().RunInMainThread([&] {
@@ -162,8 +161,17 @@ void QtInstanceMenu::insert(int nPos, const OUString& rId, 
const OUString& rStr,
 
         insertAction(*pAction, rId, nPos);
 
-        if (eCheckRadioFalse == TRISTATE_TRUE)
-            pAction->setCheckable(true);
+        pAction->setCheckable(eCheckRadioFalse != TRISTATE_INDET);
+        if (eCheckRadioFalse == TRISTATE_FALSE)
+        {
+            // For Qt, all mutually exclusive actions/menu entries would 
usually be put
+            // into the same QActionGroup. However, LO currently manually 
implements logic
+            // to toggle all other entries off when one gets enabled and 
doesn't use the concept of groups.
+            // Creating a separate QActionGroup for each item causes each item 
to be displayed
+            // with a radio button and leaves control for manually toggling 
on/off.
+            QActionGroup* pActionGroup = new QActionGroup(pAction);
+            pActionGroup->addAction(pAction);
+        }
 
         if (pIconName && !pIconName->isEmpty())
             pAction->setIcon(loadQPixmapIcon(*pIconName));

Reply via email to