5

Is it possible to remove the close button (see screenshot) of a QProgressDialog? I couldn't find anything useful in the docs/Google.

I use a modal QProgressDialog to show infinite process and block the GUI until a lengthy operation has completed. Because the GUI should be blocked, I don't want the user to be able to close the dialog.

enter image description here

demonplus
  • 5,613
  • 12
  • 49
  • 68
sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

11

You can hide close button of every window by clearing an appropriate flag:

With Qt 5.0

QProgressDialog dlg;
dlg.setWindowFlags(dlg.windowFlags() & ~Qt::WindowCloseButtonHint);

Qt::WindowCloseButtonHint 0x08000000 Adds a close button. On some platforms this implies Qt::WindowSystemMenuHint for it to work.

With earlier versions

    QProgressDialog dlg;
    dlg.setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);

where

  • Qt::Window stands for window
  • Qt::WindowTitleHint stands for displaying title on the top of the window
  • Qt::CustomizeWindowHint stands for not displaying buttons
Community
  • 1
  • 1
Lol4t0
  • 12,444
  • 4
  • 29
  • 65
  • Hm, it didn't work. May be it's because I use `QProgressDialog::exec()` to show the dialog? – sashoalm Jun 04 '13 at 14:38
  • @sashoalm, In windows, button stays visible, but you are unable to press it. You probably should also hide help button to make it invisible. I've tested it with `exec` also. What is your behavior like? – Lol4t0 Jun 04 '13 at 14:40
  • When I paste your code as-is, the close button stays and is not disabled. When I remove the flag for help button and close button, the help button disappears, but the close button stays (and is clickable). – sashoalm Jun 04 '13 at 14:46
  • @sashoalm, do you use Linux? May be your windows manager does not support this feature. You can try playing with flags. For example, this `dlg.setWindowFlags(Qt::WindowTitleHint | Qt::Window | Qt::CustomizeWindowHint);` produces an window without buttons at all, and `Qt::Popup` produces windows without border. – Lol4t0 Jun 04 '13 at 14:55
  • 1
    No, I'm on Windows 7. Is it working on your computer? This worked for me - `dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint);`, from this answer - http://stackoverflow.com/a/15656707/492336 – sashoalm Jun 04 '13 at 15:00
  • @sashoalm, I found it works with Qt 5.0 but does not with Qt 4.8 – Lol4t0 Jun 04 '13 at 15:08