Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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 was setWindowFlags(windowFlags() ^ Qt::WindowMinimizeButtonHint); and setWindowFlags(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 neither dialog->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!


  • Moderators

    @l3u_
    try windowFlags() | 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 default Qt::Dialog), which gives me a window bar button for the dialog. Then, minimizing is no problem anymore :-)



  • Sadly, the same code behaves different on Windows: The dialog does not get it's own window bar button, and it's also always on top of the parent (main window) …


  • Moderators

    Yes, sadly the window manager may simply choose to ignore the hints. Try either:

    1. Not giving the dialog a parent, so it's a top-level (native) widget.
      or
    2. 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);
    }

Log in to reply