Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Adding a QAction to a QMenu on a certain position
In my app I have a QWidget that has as a parent a QMenu. I want to add an QAction on that menu under QWidget. Do you know how to position my QAction on a certain spot into the menu? The only solution seems to add fake actions to that menu till my QAction become visible...
I think that a QAction::setGeometry() can be useful in this case...
kalle last edited by
Are you talking about the relative position ("this action should be the third in the menu") or the absolute position ("this action should be displayed 30 pixels from the top of the menu")?
Both of them could be useful :) so if you know a solution for one of them please post.
Guest last edited by
can you attach simple screenshot/mockup as to how you want it to look .. for both options?
@QToolButton* button = new QToolButton( parent );
QMenu* menu = new QMenu( button );
menu->setMinimumHeight( 140 );
menu->setMinimumWidth( 152 );
QWidget* widget = new QWidget( menu );
widget->setGeometry( 0, 0, 152, 113 );@
now I would like to add a QAction to my menu under the widget but all I can do is:
@QAction* action = new QAction( "Action",menu );
menu->addAction( action ) @
my action here it's not visible because the widget overlapped it, so to became visible I was needed to do:
@QAction* fakeAction = new QAction( QString() ,menu );
/* add fake actions till the wanted action is visible*/
menu->addAction( fakeAction );
/* add the wanted action at the end*/
menu->addAction( action );@
I would like to have :
@action->setGeometry( 0,113,152,140 );
menu->addAction( action, indexPositionInMenu );//if we can't have different heights for more actions@