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.

-
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.

-
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. -
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.

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.
-
@yjx-30k It is not clear what exactly you are doing (code) and what exact warning you get. Please provide more precise information.
@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.

-
@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.@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 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.

-
Are you talking about the menu in the standard MenuBar of
QMainWindow?
So you want to color it or change the style in other ways?
What about stylesheet?
Like here@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.