Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QAction in toolbar and menu - refresh problem
maybe someone can help as I am a newbie in Qt...
I have a set of checkable QActions grouped in a QActionGroup. This ActionGroup is added to a menu and to a toolbar. From a functional point of view everthing works fine.
The problem is:
When checking the toolbar button and then opening the menu, the belonging menu item is also checked -> ok
When checking a menu item, the belonging toolbar button won't be checked -> bad
It tried no for a quite while, but I couldn't make it. Also I'm not able to set the (visual) state of these toolbar buttons with setChecked() in the program...
Any help would be appreciated!
mchinand last edited by
setExclusive(true)for your QActionGroup? If so, and your QMenu item that contains the other checkable items is also part of the group, then you will get your observed behavior. Remove the top-level menu item from the group. You can set up logic to check that item if one of the sub-items is checked.
Thank You for your reply!
.. yes, the actions are exclusiv (default beahviour) - and no, the action group only holds sub items of the top level menu ... mmh
The toolbar and menu is hidden (and shown) as the user switches the view in the main window. Could the problem relate to this?
Hi and welcome to devnet,
Can you provide a minimal buildable sample code that shows that behaviour ?
- What version of Qt are you using ?
- What OS are you running ?
... thank you for your warm welcome!
It's quite a big engineering software - and I my knowledge is not enough to extract just this part to show the problem... I'm using Qt 5.12.1 on Windows 10.
Looking at the effect it seems, that QAction object lost it's "link" to the toolbar button widget - whereas the button is still linked to the Action object...
... problem solved.
There was a bug in the program. The QAction objects were re-created twice but then not re-assigned to the toolbar object, but re-assigned to the menu...
Thank You for your support!