Adding a QAction to a QMenu on a certain position
-
wrote on 13 Oct 2010, 07:16 last edited by
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... -
wrote on 13 Oct 2010, 09:07 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")?
-
wrote on 13 Oct 2010, 09:16 last edited by
Both of them could be useful :) so if you know a solution for one of them please post.
Thanks! -
wrote on 13 Oct 2010, 13:41 last edited by
can you attach simple screenshot/mockup as to how you want it to look .. for both options?
-
wrote on 13 Oct 2010, 14:02 last edited by
@QToolButton* button = new QToolButton( parent );
QMenu* menu = new QMenu( button );
menu->setMinimumHeight( 140 );
menu->setMinimumWidth( 152 );
button->setMenu( menu);
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 );
//or
menu->addAction( action, indexPositionInMenu );//if we can't have different heights for more actions@
1/5