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

QProgressDialog: can't disable "close window" button on mac?



  • so i try to do this:

    qDlgP->setWindowFlags(qDlgP->windowFlags() & ~Qt::WindowCloseButtonHint);
    

    and on Windows the "X" in the upper right is grayed out (can't click it).

    when i try the same on mac, the red dot in the upper left is still available. it's NOT documented that i must choose that option on window creation, that it can't be changed after the fact, so ... ?

    but if it MUST be done at window creation, what are the DEFAULT flags i should pass in, minus WindowCloseButtonHint? i can't find that either.



  • okay the special sauce for this one is you have to add in:

    Qt::CustomizeWindowHint
    

    i'm surprised, but okay.

    it's like, "here's this obvious api you can use. but you can't use it until you enable its use by using this other, obscure api"

    :D



  • okay after some investigation these are the default window flags:

      Qt::Window 
    | Qt::WindowTitleHint
    | Qt::WindowSystemMenuHint
    | Qt::WindowContextHelpButtonHint 
    | Qt::WindowCloseButtonHint;
    

    just add Qt::Dialog for a dialog.

    but i also discovered that it does NOT matter if i pass the flags (minus WindowCloseButtonHint) when constructing the dialog, the close button is still there, and enabled, and it closes the dialog.

    am i missing something?



  • okay the special sauce for this one is you have to add in:

    Qt::CustomizeWindowHint
    

    i'm surprised, but okay.

    it's like, "here's this obvious api you can use. but you can't use it until you enable its use by using this other, obscure api"

    :D


  • Moderators

    Bear in mind this is platform specific (actually window manager specific). Qt passes the hints to the window manager, but the latter may choose to ignore them! So it isn't exactly portable to depend on the behaviour.



  • well, it works on mac and windows, which is what i care about


  • Moderators

    @davecotter said in QProgressDialog: can't disable "close window" button on mac?:

    well, it works on mac and windows, which is what i care about

    Fair enough. I'm just saying it may stop working for some future version of mac or windows. Also as a note, this doesn't disable the system menu (the one you get by right-clicking on the application icon) on windows, at least last time I checked. It's completely controlled by the OS and can't be removed, keep that in mind.


Log in to reply