How to Enable/Disable Qt Close Button

You can use the following piece of code in your Qt Window to disable Close (“X”) button in the title bar.

setWindowFlags(Qt::Window
	| Qt::WindowMinimizeButtonHint
	| Qt::WindowMaximizeButtonHint);

Alternatively, you can use this code to enable it:

setWindowFlags(Qt::Window
	| Qt::WindowMinimizeButtonHint
	| Qt::WindowMaximizeButtonHint
	| Qt::WindowCloseButtonHint);

As you can see, WindowCloseButtonHint flag is responsible for enabling/disabling Close button in title bar.



2 Replies to “How to Enable/Disable Qt Close Button”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.