Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Adding a QAction to a QMenu on a certain position

Adding a QAction to a QMenu on a certain position

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 7.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sorin
    wrote on last edited by
    #1

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

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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kalle
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sorin
        wrote on last edited by
        #3

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

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

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sorin
            wrote on last edited by
            #5

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

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved