Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved [SOLVED] Add QAction into QMenuBar in Designer

    General and Desktop
    qmenubar qaction qtdesigner
    2
    5
    5634
    Loading More Posts
    • 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.
    • M
      matobodo last edited by matobodo

      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);
      
      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by Chris Kawa

        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.

        1 Reply Last reply Reply Quote 0
        • M
          matobodo last edited by

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

          1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            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).

            1 Reply Last reply Reply Quote 1
            • M
              matobodo last edited by

              Ok, thanks.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post