QMenu use menuaction
-
I want to that QMenu don't add any action , use itself menuaction,I am trying to implement the triggering operation of the menu action, but I keep receiving warnings that the menu action signal is not being received.Do you have any suggestions? Because I want to implement a special effect.
-
@yjx-30k said in QMenu use menuaction:
I want to that QMenu don't add any action
but I keep receiving warnings that the menu action signal is not being received
If I'm not mistaken, the function you are referring to is just the getter for the associated
QAction
. Since you dont set any action, you cant receive any signals.
Just a guess... for more details please post the code what exactly you are doing. -
Hi,
If you don't want to add any actions to your
QMenu
, but still want to receive a signal when it is clicked, you could take a look at this:Basically, you'd have to use QMenu::aboutToHide and QMenu::aboutToShow signals instead of QMenu::triggered
connect(ui->yourMenu, &QMenu::aboutToHide, [this](){ //do something }); connect(ui->yourMenu, &QMenu::aboutToShow, [this](){ //do something });
A comment there says:
with that there is a bug here, when moving mouse on this menu, without clicking, the slot trigering automatically.
I couldn't reproduce that behavior.
-
@jsulm I want to achieve a special effect using a menu. Previously, I used an action to do it, but I found that clicking between the action and other menus caused a position shifting phenomenon. I want to solve this problem, but I cannot add any additional actions to the menu because it will form a context menu. I just want to use this special menu with color as a button. Overriding the resize event of the menuBar is too complicated.
-
@Pl45m4 I want to achieve a special effect using a menu. Previously, I used an action to do it, but I found that clicking between the action and other menus caused a position shifting phenomenon. I want to solve this problem, but I cannot add any additional actions to the menu because it will form a context menu. I just want to use this special menu with color as a button. Overriding the resize event of the menuBar is too complicated.
-
-
@Pl45m4 Thank you, but I am facing a more serious problem. I want to achieve the effect of clicking and checked attribute on the menu to switch pages. I did this through aboutToShow(), but I found that triggering would be automatically triggered when the mouse moved over the menu. Do you have a better solution? I also searched on Stack Overflow, but unfortunately there was no good solution. Link: https://stackoverflow.com/questions/22197496/how-to-perform-action-on-clicking-a-qmenu-object-only/22197619#22197619.
-
Are you trying to make a QTabWidget?
It sounds (and looks) like you're trying to use the menubar as a tab bar.