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. Menu and subMenu
Forum Updated to NodeBB v4.3 + New Features

Menu and subMenu

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 7.2k Views 1 Watching
  • 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
    saam_6066
    wrote on last edited by
    #1

    Hi,

    I have a main menu that I need to update it in run time, I want to add a submenu to it whenever a special node is added to the scene so that the user can see the node name in the submenu and do some actions based on that. I searched a lot but couldn't find a good way to do this in my application. I will be glad if someone can help me with it.

    Thanks!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mmallad
      wrote on last edited by
      #2

      You can use QAction to make new action and add it to the menu with addAction function and you can connect to triggered signal to do some action.
      @
      QAction *action = new QAction(tr("New Sub Menu"),this);
      action->setShortcut(Qt::CTRL | Qt::Key_M);
      connect(action, SIGNAL(triggerSignalHere()), this, SLOT(youSlotHere()));
      yourMainMenu->addAction(action);
      @

      Dpak Malla

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

        Thanks for the answer but I want to have sth like this:

        a main menu with the following:

        Delete
        Move to right
        Move to left
        Add to ....

        where add to... is a sub menu containing the following:

        "Add to ..." :
        processor 1
        processor 2
        .
        .
        .

        "Add to .. " menu is added in real-time whenever a new processor is created in the graphicsscene. and I have to avoid adding "Add to.. " multiple times.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Take a look at this example. Maybe it will help you:
          @
          //of course don't use globals, this is just an example
          QMenu* menu = new QMenu( someParent );
          menu->addAction("Delete");
          menu->addAction("Move to right");
          menu->addAction("Move to left");
          QAction* addEntry = menu->addAction("Add to...");

          QMenu* procmenu = new QMenu(...);
          addEntry->setMenu(procmenu);

          void addProcessor()
          {
          procmenu->addAction("Processor " + QString::number(procmenu->actions().size() + 1));
          }

          void showMenu(QPoint pt)
          {
          addEntry->setVisible( procmenu->actions().size() > 0 );
          menu->popup(pt);
          }

          //and then use it:
          addProcessor();
          addProcessor();
          showMenu(QPoint(x,y));
          @
          Similarly you can add removeProcessor() etc.

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

            Thanks for the answer! it solved my problem! :)

            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