How to disable the close button of a QProgressDialog?

  • I'm trying to create a QProgressDialog on OS X with the close button disabled. I'm using the following code:

    QProgressDialog progressDialog = new QProgressDialog(tr("Calculating..."), NULL, 0, 100, this);
    progressDialog->setWindowTitle(tr("Calculate Weights"));
    progressDialog->setWindowFlags(progressDialog->windowFlags() & ~Qt::WindowCloseButtonHint);

    But it is not working on OS X, the close button is still there and is available. Note that it works well on Windows.

    I'm using Qt 5.3.

    Any idea on how can I solve it?

    Thanks in advance

  • @KelvinSP

    Create a custom push button

    Disable that button with setDisable()

    set the Cancel push button by void QProgressDialog::setCancelButton(QPushButton * cancelButton)

    Enable it when you want.

    Kind Regards,


  • @Charlie_Hdz

    Thanks for the help.
    Actually, I don't want to disable the cancel button.
    I want to disable the 'native window close button' (the X option from the left upper corner).

  • @KelvinSP it looks like your looking at "window flags". You may want to take a look at this example showing how the hints apply to a widget

  • @Pablo-J.-Rogina thanks a lot. "Window flags" are exactly what I'm looking for.

    The problem here is that I'm using the Qt::WindowCloseButtonHint flag to 'block' the native close button of a QProgressDialog and it works well on Windows but it does not block the close button on OS X. I have tried other flags but none of them worked as expected.

  • Qt Champions 2016

    Qt has no control over how the window manager treats the window flags. The OSX window manager may simply ignore what you "hint" with the flags and add the close button anyway. From the docs:

    Some of these flags depend on whether the underlying window manager supports them.

  • @kshegunov thanks, it makes sense. So, there is no window flag which can accomplish this task on OS X?

  • Qt Champions 2016

    There are no window flags that are guaranteed to be respected. I don't work on OSX, so someone may correct me, but if it doesn't respect your hint I don't think you can do much about it.

  • dlg->setWindowFlags(Qt::WindowTitleHint); X button is blocked. try

  • @Taz742 it doesn't work as expected. I just want to keep the X (close) button disable/unavailable. Thanks.

  • I finally found a solution. It worked well with the following combination of flags:

    progressDialog->setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint);

    Thank you so much for all help.

  • Excellent! Please don't forget to mark your post as solved. Cheers

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.