artoon
artoon

Reputation: 739

QMessageBox Yes, No, close

First I have a QMessageBox and I would like hide the red cross (close). I tried with the WindowFlags but I didn't manage.

Secondly, this QMessageBox can't be closed by the user but it can be closed by the code. And when it is closing I wouldn't like it execute the code on the answer No (or Yes).

Upvotes: 1

Views: 1751

Answers (2)

Yann Go
Yann Go

Reputation: 1

This works:

// Remove Window Close X icon
msgBox.setWindowFlags(Qt::WindowTitleHint | Qt::FramelessWindowHint); 

Upvotes: 0

fleed
fleed

Reputation: 680

Don't you need to turn off the WindowCloseButtonHint? So something like

mbox.setWindowFlags(mbox.windowFlags() ^ Qt::WindowCloseButtonHint);

If you can get away with using the standard functionality with something like this then it's less code to go wrong and less to maintain for you.

Upvotes: 0

Related Questions