Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] Add QAction into QMenuBar in Designer



  • Is it possible to add QAction into QMenuBar in the Designer? I haven't found any way to do it. The only way I know is to write this code but I want to do it in the designer:

        QAction *action = new QAction("My action");
        ui->menuBar->addAction(action);
    

  • Moderators

    The designer only supports menu bars on a QMainWindow, so if you're using a QDialog or a plain QWidget you're out of luck.
    If you're using a QMainWindow based widget you can just drag and drop the action from the actions panel to the menu bar.



  • I have menu bar in the main window, but drag and drop the action is not working:
    https://www.youtube.com/watch?v=ujmShlPqhMs


  • Moderators

    Ah, ok, I misunderstood. You can't do that using the designer indeed. I can only speculate why that is but I suspect that's because it's uncommon to have an action on a menu bar. Actions usually go on tool bars and menu bars have, well, menus.

    You can create a menu typing in the "Type here" field. You can then add action to that menu via drag&drop but you can't put an action directly on the menu bar. Just a designer limitation (one of many).



  • Ok, thanks.