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. Get item in dynamic menu
Qt 6.11 is out! See what's new in the release blog

Get item in dynamic menu

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.1k 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.
  • X Offline
    X Offline
    xkiz
    wrote on last edited by
    #1

    I'm very new in Qt and I'm stuck with Qmenu functionallity, I need to create a dynamic menu attached to an Action, I don't know how to get wich item I clicked

    @
    ui->mainToolBar->addAction(ui->actionPlus);
    AddItems = new QMenu;
    for(int i = 0; i < 10; i++){// just for testing
    AddItems->addAction("Item " + QString::number(i), this, SLOT(AddItems_triggered()));
    }//....
    ui->actionPlus->setMenu(AddItems);
    //.....
    void MainWindow::AddItems_triggered()
    {
    qDebug() << "testing....";
    }
    @

    is there a way to get the menu Item clicked of the menu?
    I'm Lost, I keep Searching but I allway get the same search results

    Sent from Ubuntu

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should use QMenu::triggered(QAction *)

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xkiz
        wrote on last edited by
        #3

        based on your answer, I google again, and I got this: http://stackoverflow.com/questions/9187538/qt-how-to-add-a-list-of-qactions-to-qmenu-and-handle-them-with-a-single-slot

        from where I could get this:
        @
        for(int i = 1; i < 3; i++){
        QAction action = new QAction("Item " + QString::number(i),this);
        action->setData(i);
        AddItems->addAction(action);
        }
        AddItems->addSeparator();
        AddItems->addAction("Other Items 1", this, SLOT(tempFuncd()));
        AddItems->addAction("Other Items 2", this, SLOT(tempFuncd2()));
        connect(AddItems, SIGNAL(triggered(QAction
        )), this, SLOT(AddItems_triggered(QAction*)));
        @

        I guest that in the AddItems_triggered function I could do a switch to do something or just ignore

        Sent from Ubuntu

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You could also use a "QSignalMapper":http://qt-project.org/doc/qt-4.8/qsignalmapper.html

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xkiz
            wrote on last edited by
            #5

            sorry to bother but, could u put a link where I could see an example of this?
            I'm Lost here,

            Sent from Ubuntu

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              "Qt Quarterly 10":http://doc.qt.digia.com/qq/qq10-signalmapper.html

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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