I need to add a QAction directly into a QMenuBar (not an QAction inside a QMenu but a QAction directly in the QMenuBar) I am able to do this with the following command.
ui->menuBar->addAction(“VFTP”,this, SLOT(VFTPmenuTrigger()) );
My only problem is that when I add it, it is appended to the end of the menu bar that I have built in Qt designer. I would like to be able to put it somewhere in the middle. Seems the only way I could do this is if I generate the menu bar by coding it only. Is there a way to build most of my menuBar in Qt Designer and then add that Qaction in the menu bar where I want? I hope I am clear and I added the QAction programmatically because it is not possible to do so with Qt (I know it sounds countintuitive to put a QAction directly in the menu bar but this is what the customer wants)
If you look at
QMenuBarcode you’ll that it does this:which basically uses
QWidget::addAction(). So it stands to reason that you can useQWidget::insertAction()yourself to do the same thing.insertAction()lets you specify before whatQActionyou want to add.