Add maximize button to QDialog frame
-
wrote on 18 Jul 2019, 17:06 last edited by
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!
-
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!
wrote on 18 Jul 2019, 17:44 last edited by@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.
-
@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.
wrote on 18 Jul 2019, 20:58 last edited by@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.
-
@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.
wrote on 18 Jul 2019, 21:48 last edited by Pl45m4Check 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. -
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.wrote on 19 Jul 2019, 07:27 last edited by@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.
-
wrote on 19 Jul 2019, 10:46 last edited by
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 toIgnored
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/6