QMenu C++ code help
-
This post is deleted!
-
@AnneRanch
I think many people in this forum are willing to do that.
The way it works is as follows:- show code
- explain what's the expected behavior
- show error messages, if they exist
- take advice, change the implementation accordingly
- show more / other parts of the code, if asked to
The way it doesn't work is like in this post, where unwanted arrows in a menu were reported. I asked for a screenshot of those arrows. Your response was, that screenshots of menus can't be made at all. You also insinuated that I should be aware of this restriction, and therefore I should not have asked for the impossible. I explained you how to make a screenshot of menus on your operating system. You may deem the screenshot irrelevant. Maybe it is. But it helps understand what you are aiming at and it expedites getting a solution. Co-operation is in your hands, not in ours.
I am neither judging nor analyzing you. I am just stating, which effect some posts have on me and maybe other members of the community: They bounce me off.
It's never too late for a fresh start.
Ready for it? -
This post is deleted!
-
@AnneRanch
As per @Axel-Spoerl's answer to you at https://forum.qt.io/topic/153820/qmenu-qaction-how-can-i-add-checked/2, you must have created aQAction
for theQMenu
to put a checkbox on it. He gave the code for that there.Thereafter you can access either (a) by maintaining (e.g. as a class member variable) the
QAction *
pointer to theQAction
you created and added to theQMenu
or (b) from aQMenu
you can get at all its actions viamenu->actions()
. If you know the one you want is the only/first one, then obviously:QAction *action = menu->actions().at(0); // assumes at least one action has been added action->setChecked(true);
-
@AnneRanch said in QMenu C++ code help:
That is the issue - how to change "checkable" property when there is access only to QMenu.
That is what you wrote. So I took the time to answer it exactly.
You cannot get directly from a
QAction *
to theQMenu
you put it on, unlike the other way round which you asked and is answered. However, you can use QList<QObject *> QAction::associatedObjects() const from aQAction
and you should find theQMenu
it has been added to among them. And you add submenus to a menu. Which answers the new question.