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. How to add a Menu in a QDialog window
Forum Updated to NodeBB v4.3 + New Features

How to add a Menu in a QDialog window

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 3.2k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fem_dev
    wrote on last edited by
    #1

    My Qt application will be more than one single window, and each window will be your own drop down menus and toolbars.

    I would like to know:
    1- What is the best:
    a) Create just one single QMainWindow for the main window and the others will be QDialog windows.
    b) Create multiple QMainWindows, one for each window

    2- If the a response is better, how can I add these 2 things in a QDialog window:

    • Drop Down menu...like File->Open
    • Toolbar...with icons such new file, save, printer, etc...
    JonBJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      There is nothing against using multiple mainwindows, however
      they are not blocking as a Dialog would/could.
      The user can at any time click on any open window.
      So if that is ok, i would go with MainWindows.

      If you want to go the Dialog way, you will have to insert some layouts to the dialog to keep both QMenu and QStatusbar where they normally are.

      1 Reply Last reply
      1
      • F fem_dev

        My Qt application will be more than one single window, and each window will be your own drop down menus and toolbars.

        I would like to know:
        1- What is the best:
        a) Create just one single QMainWindow for the main window and the others will be QDialog windows.
        b) Create multiple QMainWindows, one for each window

        2- If the a response is better, how can I add these 2 things in a QDialog window:

        • Drop Down menu...like File->Open
        • Toolbar...with icons such new file, save, printer, etc...
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @fem_dev
        Assuming you do want independent multiple windows, not dialogs. You can create multiple QMainWindows, that just a style. When you say you want "each window will be your own drop down menus and toolbars", you can do that, but you may run out of screen space, and it can be difficult for the user to keep track of which windows he has open where.

        Have you considered whether https://doc.qt.io/qt-5/qmdiarea.html would give what you are seeking neatly? Look at the picture in https://doc.qt.io/qt-5/qtwidgets-mainwindows-mdi-example.html. In MDI you have multiple independent windows, inside an enclosing scrollable frame, and they share a single menu/toolbar on that frame. Depending on which window is currently up-front/active, the menu/toolbar changes to offer the appropriate items in the menu/toolbar. I know MDI is a bit out-of-fashion these days, but for what you are seeking it may be just what you want?

        1 Reply Last reply
        1
        • F Offline
          F Offline
          fem_dev
          wrote on last edited by fem_dev
          #4

          Thank you @mrjj ...I think that will be good to block user click in the MainWindow when the second window is enable. So QDialog will be better for my case.

          I'm newer in Qt and I don't know how to add QMenu in the layout. Should I do this in the Qt Creator Designer or by code?
          Beyond the drop-down menu (File->Open, etc...) is possible to create a UI Toolbar at the top of the QDialog window? With some icons like "New File", "Save", etc...?

          How can I do that? Is there any examples?

          I already tried this, but doesn't work:

          QVBoxLayout *mainLayout = new QVBoxLayout(this);
          
          QToolBar *toolBar = new QToolBar();
          mainLayout->addWidget(toolBar);
          
          QAction *action1 = new QAction("Add", toolBar);
          QAction *action2 = new QAction("Del", toolBar);
          

          Thank you @JonB too.
          Very interesting point! I will use that in the future projects.

          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