14

Is it possible to disable/delete the QDialogs default close button at the upper left of the dialog?

Whitewall
  • 597
  • 1
  • 7
  • 18
Streight
  • 811
  • 4
  • 15
  • 28

5 Answers5

10

At least in (embedded) Linux, you can do this:

setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);

With that, I get a window which has the title but no buttons.

hcarver
  • 7,126
  • 4
  • 41
  • 67
user3912842
  • 101
  • 1
  • 2
  • 1
    This is the way. But don't forget to also handle the Escape key which closes the dialog (if your goal is to make it not dismissible by user). – Violet Giraffe Mar 22 '22 at 11:52
3

Use this function for your dialog

dlgLobLobLob->setWindowFlags(Qt::Dialog | Qt::Desktop)
Mohammad Sheykholeslam
  • 1,379
  • 5
  • 18
  • 35
  • 2
    I tried that, but unfortunately it does not work - all buttons (close, maximize, minimize) are available. Guess it depends on the Unity Desktop. – Streight Apr 29 '12 at 10:47
3

Try setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint); . You may want to check the Window Flags Example, and play around to see effects of all possible combinations of WindowFlags

YamHon.CHAN
  • 866
  • 4
  • 20
  • 36
3

Clearing WindowCloseButtonHint in WindowFlags may do what you want. Check out the example here.

Stephen Chu
  • 12,724
  • 1
  • 35
  • 46
  • 2
    I tried now to costumize the window by `setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint);` or `setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);` . Problem is, that both ideas still leave the maximize button and when maximized the close button appears again. Any idea? – Streight Apr 01 '12 at 22:20
0

This worked for me:

setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint)

Marek
  • 21
  • 3
  • This is *very* similar to other answers (like [this one](https://stackoverflow.com/a/25152802/10871073)), posted some years ago. Maybe you should add some explanation as to how/why it is better than any existing answer. – Adrian Mole Oct 04 '21 at 10:10
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/29988909) – Toni Oct 04 '21 at 12:13