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. Change existing menu from menubar

Change existing menu from menubar

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 1.2k 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.
  • H Offline
    H Offline
    hobbyProgrammer
    wrote on last edited by
    #1

    Hi,
    I am creating an app where I'd like to have a menu that is dynamic.
    The QActions that need to be in that menu are pulled from the database. Therefore it can be 0 QActions, but there can also be 10 items.
    Let's say it's a list of employees. The title is menuEmployee and the submenu's need to be pulled from the database.

    How do I do this? (I know how to pull the data from the database and dynamically create the actions, but i don't know how to add it to the existing menuEmployee.

    menuEmployee is the 3rd menu of the menubar (idk if that's useful information).

    jsulmJ 1 Reply Last reply
    0
    • H hobbyProgrammer

      @jsulm I can't edit it programmatically. Only in the designer.

      Whenever I try this:

      ui->menubar->menuEmployee->addAction(action);
      it says:

      "no member names 'menuEmployee' in 'QMenuBar' "

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @hobbyProgrammer Does

      ui->menuEmployee->addAction(action);
      

      work?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 1 Reply Last reply
      4
      • H hobbyProgrammer

        Hi,
        I am creating an app where I'd like to have a menu that is dynamic.
        The QActions that need to be in that menu are pulled from the database. Therefore it can be 0 QActions, but there can also be 10 items.
        Let's say it's a list of employees. The title is menuEmployee and the submenu's need to be pulled from the database.

        How do I do this? (I know how to pull the data from the database and dynamically create the actions, but i don't know how to add it to the existing menuEmployee.

        menuEmployee is the 3rd menu of the menubar (idk if that's useful information).

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @hobbyProgrammer said in Change existing menu from menubar:

        but i don't know how to add it to the existing menuEmployee

        call addAction on the menu as shown here: https://doc.qt.io/qt-5/qaction.html

        const QIcon openIcon = QIcon::fromTheme("document-open", QIcon(":/images/open.png"));
            QAction *openAct = new QAction(openIcon, tr("&Open..."), this);
            openAct->setShortcuts(QKeySequence::Open);
            openAct->setStatusTip(tr("Open an existing file"));
            connect(openAct, &QAction::triggered, this, &MainWindow::open);
            fileMenu->addAction(openAct); // HERE
            fileToolBar->addAction(openAct);
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        H 1 Reply Last reply
        0
        • jsulmJ jsulm

          @hobbyProgrammer said in Change existing menu from menubar:

          but i don't know how to add it to the existing menuEmployee

          call addAction on the menu as shown here: https://doc.qt.io/qt-5/qaction.html

          const QIcon openIcon = QIcon::fromTheme("document-open", QIcon(":/images/open.png"));
              QAction *openAct = new QAction(openIcon, tr("&Open..."), this);
              openAct->setShortcuts(QKeySequence::Open);
              openAct->setStatusTip(tr("Open an existing file"));
              connect(openAct, &QAction::triggered, this, &MainWindow::open);
              fileMenu->addAction(openAct); // HERE
              fileToolBar->addAction(openAct);
          
          H Offline
          H Offline
          hobbyProgrammer
          wrote on last edited by hobbyProgrammer
          #3

          @jsulm Hi,

          yes I know how to do that, but my menu is inside the menubar of my ui so I assume it would work like this:

          ui->menubar->menuEmployee->addAction(action);

          but that doesn't work. There isn't a QMenu in my h files either.

          jsulmJ 1 Reply Last reply
          0
          • H hobbyProgrammer

            @jsulm Hi,

            yes I know how to do that, but my menu is inside the menubar of my ui so I assume it would work like this:

            ui->menubar->menuEmployee->addAction(action);

            but that doesn't work. There isn't a QMenu in my h files either.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @hobbyProgrammer said in Change existing menu from menubar:

            but that doesn't work. There isn't a QMenu in my h files either.

            I don't get it: does ui->menubar->menuEmployee exist? If so: what does not work?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            H 1 Reply Last reply
            0
            • jsulmJ jsulm

              @hobbyProgrammer said in Change existing menu from menubar:

              but that doesn't work. There isn't a QMenu in my h files either.

              I don't get it: does ui->menubar->menuEmployee exist? If so: what does not work?

              H Offline
              H Offline
              hobbyProgrammer
              wrote on last edited by
              #5

              @jsulm
              it looks like it exists...
              0b829d32-8055-4ead-a9c5-b66241cf0f55-image.png

              jsulmJ 1 Reply Last reply
              0
              • H hobbyProgrammer

                @jsulm
                it looks like it exists...
                0b829d32-8055-4ead-a9c5-b66241cf0f55-image.png

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @hobbyProgrammer said in Change existing menu from menubar:

                it looks like it exists

                Then what does not work?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @hobbyProgrammer said in Change existing menu from menubar:

                  it looks like it exists

                  Then what does not work?

                  H Offline
                  H Offline
                  hobbyProgrammer
                  wrote on last edited by
                  #7

                  @jsulm I can't edit it programmatically. Only in the designer.

                  Whenever I try this:

                  ui->menubar->menuEmployee->addAction(action);
                  it says:

                  "no member names 'menuEmployee' in 'QMenuBar' "

                  jsulmJ 1 Reply Last reply
                  0
                  • H hobbyProgrammer

                    @jsulm I can't edit it programmatically. Only in the designer.

                    Whenever I try this:

                    ui->menubar->menuEmployee->addAction(action);
                    it says:

                    "no member names 'menuEmployee' in 'QMenuBar' "

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @hobbyProgrammer Does

                    ui->menuEmployee->addAction(action);
                    

                    work?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply
                    4
                    • jsulmJ jsulm

                      @hobbyProgrammer Does

                      ui->menuEmployee->addAction(action);
                      

                      work?

                      H Offline
                      H Offline
                      hobbyProgrammer
                      wrote on last edited by
                      #9

                      @jsulm yep, that was a stupid mistake :')
                      thank you so much!

                      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