Trouble removing the minimize button from a QDialog
-
Hi :-)
I have a non-modal QDialog. I'm on Linux/KDE (but alas, I need the result also to be working on Windows). Problem ist that the dialog has a minimize button, and when the user presses it, the window disappears without being listed in the window bar. One has to minimize and restore the main window to re-show the dialog.
Thus, I want to hide the minimize button.
I tried to play with
Qt::WindowMinimizeButtonHint
, but I didn't get it to work (what I found wassetWindowFlags(windowFlags() ^ Qt::WindowMinimizeButtonHint);
andsetWindowFlags(windowFlags() & ~Qt::WindowMinimizeButtonHint);
, both had no effect).I then found
setWindowFlags(Qt::Tool)
. this actually removes the minimize button, but the problem is that the dialog window is not focused after being shown and neitherdialog->raise()
,dialog->activateWindow();
nor a combination of both select the window (as if the title bar would have been clicked).So I'm a bit lost at the moment ;-)
Thanks for all help!
-
@l3u_
trywindowFlags() | Qt::CustomizeWindowHint & ~Qt::WindowMinimizeButtonHint
(untested) -
@raven-worx Thanks for the hint! I solved it however by setting the window flags to
Qt::Window
(instead of the defaultQt::Dialog
), which gives me a window bar button for the dialog. Then, minimizing is no problem anymore :-) -
Yes, sadly the window manager may simply choose to ignore the hints. Try either:
- Not giving the dialog a parent, so it's a top-level (native) widget.
or - filtering the state change event to just disable the minimize (even if the button isn't hidden), something like:
bool MyDialogClass::event(QEvent * e) { if (e->type() == QEvent::WindowStateChange && (reinterpret_cast<QWindowStateChangeEvent *>(e)->oldState() & Qt::WindowMinimized) == Qt::WindowMinimized) { e->ignore(); return true; } return QDialog::event(e); }
- Not giving the dialog a parent, so it's a top-level (native) widget.