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. Trouble removing the minimize button from a QDialog
Forum Updated to NodeBB v4.3 + New Features

Trouble removing the minimize button from a QDialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.6k Views 3 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.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by
    #1

    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!

    raven-worxR 1 Reply Last reply
    0
    • l3u_L l3u_

      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!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @l3u_
      try windowFlags() | Qt::CustomizeWindowHint & ~Qt::WindowMinimizeButtonHint
      (untested)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      l3u_L 1 Reply Last reply
      4
      • raven-worxR raven-worx

        @l3u_
        try windowFlags() | Qt::CustomizeWindowHint & ~Qt::WindowMinimizeButtonHint
        (untested)

        l3u_L Offline
        l3u_L Offline
        l3u_
        wrote on last edited by
        #3

        @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 :-)

        1 Reply Last reply
        0
        • l3u_L Offline
          l3u_L Offline
          l3u_
          wrote on last edited by
          #4

          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) …

          kshegunovK 1 Reply Last reply
          0
          • l3u_L l3u_

            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) …

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            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);
            }

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            2

            • Login

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