Change existing menu from menubar
-
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).
-
-
@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);
-
@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.
-
@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?
-
@hobbyProgrammer said in Change existing menu from menubar:
it looks like it exists
Then what does not work?
-