October 13, 2010

Sorin Sorin
Lab Rat
66 posts

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…

 Signature 

There are only 10 types of people in the world: Those who understand binary, and those who don’t

4 replies

October 13, 2010

kalle kalle
Lab Rat
42 posts

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”)?

October 13, 2010

Sorin Sorin
Lab Rat
66 posts

Both of them could be useful :) so if you know a solution for one of them please post.
Thanks!

 Signature 

There are only 10 types of people in the world: Those who understand binary, and those who don’t

October 13, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

can you attach simple screenshot/mockup as to how you want it to look .. for both options?

October 13, 2010

Sorin Sorin
Lab Rat
66 posts

  1. QToolButton* button = new QToolButton( parent );
  2. QMenu* menu = new QMenu( button );
  3. menu->setMinimumHeight( 140 );
  4. menu->setMinimumWidth( 152 );
  5. button->setMenu( menu);
  6. QWidget* widget = new QWidget( menu );
  7. 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:

  1. QAction* action = new QAction( "Action",menu );
  2. menu->addAction( action )

my action here it’s not visible because the widget overlapped it, so to became visible I was needed to do:

  1. QAction* fakeAction = new QAction( QString() ,menu );
  2. /* add fake actions till the wanted action is visible*/
  3. menu->addAction( fakeAction );
  4. /* add the wanted action at the end*/
  5. menu->addAction( action );

I would like to have :

  1. action->setGeometry( 0,113,152,140 );
  2. //or
  3. menu->addAction( action, indexPositionInMenu );//if we can't have different heights for more actions

 Signature 

There are only 10 types of people in the world: Those who understand binary, and those who don’t

 
  ‹‹ [Solved] unresolved external errors: QX11Info      [SOLVED]Qt 4.7 udpsocket and encoding issue ››

You must log in to post a reply. Not a member yet? Register here!