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. Add maximize button to QDialog frame
Forum Update on Monday, May 27th 2025

Add maximize button to QDialog frame

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 6.4k Views
  • 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on 18 Jul 2019, 17:06 last edited by
    #1

    I have a dialog which inherits QDialog. According to the documentation, it is possible to customize the behavior of QDialog by setting some window flags which are parameters to the constructor of QDialog.

    I would like to add a maximize button but not a minimize button; the system window manager would presumably replace the maximize button with a "restore" button at runtime when the user maximizes the window.

    I am working with Linux Ubuntu 18.04 LTS, but the code should also eventually run on Windows 10 or later.

    In my class DlgGraphView which inherits QDialog, I have this in the initialization list:

    DlgGraphView::DlgGraphView(QWidget *parent)
      : QDialog     ( parent,
                        Qt::CustomizeWindowHint
                      | Qt::WindowSystemMenuHint
                      | Qt::WindowMaximizeButtonHint
                      | Qt::WindowCloseButtonHint)
      , (etc.)
    

    Apparently this has no effect.
    The constructor of QDialog looks like this:

    QDialog::QDialog(QWidget *parent, Qt::WindowFlags f)
        : QWidget(*new QDialogPrivate, parent,
                  f | ((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0)))
    {
    }
    

    So it looks like the flags should be honored, but they aren't. Most likely I have overlooked something?

    Thanks for any help!

    J 1 Reply Last reply 18 Jul 2019, 17:44
    0
    • R Robert Hairgrove
      18 Jul 2019, 17:06

      I have a dialog which inherits QDialog. According to the documentation, it is possible to customize the behavior of QDialog by setting some window flags which are parameters to the constructor of QDialog.

      I would like to add a maximize button but not a minimize button; the system window manager would presumably replace the maximize button with a "restore" button at runtime when the user maximizes the window.

      I am working with Linux Ubuntu 18.04 LTS, but the code should also eventually run on Windows 10 or later.

      In my class DlgGraphView which inherits QDialog, I have this in the initialization list:

      DlgGraphView::DlgGraphView(QWidget *parent)
        : QDialog     ( parent,
                          Qt::CustomizeWindowHint
                        | Qt::WindowSystemMenuHint
                        | Qt::WindowMaximizeButtonHint
                        | Qt::WindowCloseButtonHint)
        , (etc.)
      

      Apparently this has no effect.
      The constructor of QDialog looks like this:

      QDialog::QDialog(QWidget *parent, Qt::WindowFlags f)
          : QWidget(*new QDialogPrivate, parent,
                    f | ((f & Qt::WindowType_Mask) == 0 ? Qt::Dialog : Qt::WindowType(0)))
      {
      }
      

      So it looks like the flags should be honored, but they aren't. Most likely I have overlooked something?

      Thanks for any help!

      J Offline
      J Offline
      JonB
      wrote on 18 Jul 2019, 17:44 last edited by
      #2

      @Robert-Hairgrove
      At a rough glance your code looks OK. When you say "Apparently this has no effect." what do you mean? Do you see no difference at all in dialog style, or just not what you wanted?

      Whether the native windowing system honours those flags is a different matter. It may be that you can't have a maximize without a minimize. Also the Linux behaviour is desktop/window manager dependent.

      R 1 Reply Last reply 18 Jul 2019, 20:58
      1
      • J JonB
        18 Jul 2019, 17:44

        @Robert-Hairgrove
        At a rough glance your code looks OK. When you say "Apparently this has no effect." what do you mean? Do you see no difference at all in dialog style, or just not what you wanted?

        Whether the native windowing system honours those flags is a different matter. It may be that you can't have a maximize without a minimize. Also the Linux behaviour is desktop/window manager dependent.

        R Offline
        R Offline
        Robert Hairgrove
        wrote on 18 Jul 2019, 20:58 last edited by
        #3

        @JonB ... thanks for looking at this.

        My first attempt was only to set the first three enum values, i.e. without Qt::WindowCloseButtonHint because the default QDialog window frame has that built in. But then no buttons at all were shown, so I added it to the initialisation of the parent.

        I suppose I need to delve more into the Qt sources to understand what is happening.

        P 1 Reply Last reply 18 Jul 2019, 21:48
        0
        • R Robert Hairgrove
          18 Jul 2019, 20:58

          @JonB ... thanks for looking at this.

          My first attempt was only to set the first three enum values, i.e. without Qt::WindowCloseButtonHint because the default QDialog window frame has that built in. But then no buttons at all were shown, so I added it to the initialisation of the parent.

          I suppose I need to delve more into the Qt sources to understand what is happening.

          P Offline
          P Offline
          Pl45m4
          wrote on 18 Jul 2019, 21:48 last edited by Pl45m4
          #4

          @Robert-Hairgrove

          Check out this example (QWindowFlags Example).
          It is really good and you can play around with different settings until you get what you expect.
          You can switch between various types of windows (Window, Dialog...) and (if I have seen it correctly) even change or bypass X11 (may be different in MS Windows and Ubuntu).

          EDIT:
          In fact that there are two separate checkBlxes to toggle MinimizeButton and MaximizeButton, I guess it could be possible that you can use one of them, without the other.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          R 1 Reply Last reply 19 Jul 2019, 07:27
          2
          • P Pl45m4
            18 Jul 2019, 21:48

            @Robert-Hairgrove

            Check out this example (QWindowFlags Example).
            It is really good and you can play around with different settings until you get what you expect.
            You can switch between various types of windows (Window, Dialog...) and (if I have seen it correctly) even change or bypass X11 (may be different in MS Windows and Ubuntu).

            EDIT:
            In fact that there are two separate checkBlxes to toggle MinimizeButton and MaximizeButton, I guess it could be possible that you can use one of them, without the other.

            R Offline
            R Offline
            Robert Hairgrove
            wrote on 19 Jul 2019, 07:27 last edited by
            #5

            @Pl45m4 ... thank you. I tried the example, but it appears that under Ubuntu 18.04 using the default window manager, all of the custom flags are ignored except for the close button hint if the window type "Dialog" is selected.

            I think I will implement my class differently and not inherit QDialog, but QWidget or QWindow instead.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Robert Hairgrove
              wrote on 19 Jul 2019, 10:46 last edited by
              #6

              Thanks to all ... I have decided to remain with QDialog because it has so many convenient signals and slots. In the constructor, I can resize the window using QScreen, e.g.:

                // Set the window to fill the available desktop area,
                // but leave a little space to allow for resizing the dialog:
                QScreen *screen = QGuiApplication::primaryScreen();
                if (screen) {
                  QRect r = screen->availableGeometry();
                  int l,t,w,h;
                  l = t = 10;
                  w = r.width() - 2*l;
                  h = r.height() - 2*t;
                  this->setGeometry(l,t,w,h);
                }
              

              Also, it was necessary to set the sizePolicy of the dialog to Ignored in order to allow the user to resize it without it jumping back to the default dimensions.

              So I am now marking this as "Solved".

              1 Reply Last reply
              0

              1/6

              18 Jul 2019, 17:06

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved