zar
zar

Reputation: 12227

How to disable the close button of window using Qt?

I want to disable the close button on the window (main application window) when an operation starts so user can't exit the application and enable it again when the operation is complete. How can I do that in Qt application? My platform is windows 7.

Alternatively I could show a message if user press close button and exiting application that a process is running in the background and abort closing the application.

How can I do either?

Upvotes: 5

Views: 10586

Answers (1)

Jablonski
Jablonski

Reputation: 18504

If you want disable button, you can use next:

auto flags = windowFlags();//save current configuration
//your main configuration which do the trick
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint );
//...
setWindowFlags(flags);//restore

If you are sure that such "feature" will not irritate your users, you can use this, in another case use link from the comment.

Upvotes: 5

Related Questions