Theodore Tang
Theodore Tang

Reputation: 1021

QMessageBox without Icon

Normally, when creating a QMessageBox, the window icon will look like this:

enter image description here

But I want to have a QMessageBox without the window/title bar icon, like this:

enter image description here

I did some research and saw that I have to use QMessageBox::NoIcon. I tried, but it did not really work out.

So what can I do to remove the QMessageBox icon?

Upvotes: 1

Views: 3950

Answers (1)

IAmInPLS
IAmInPLS

Reputation: 4125

QMessageBox::NoIcon is not for the title bar icon: it's for the big icon in your message box.

In order to remove the title bar icon, you have to set specific flags:

QMessageBox msgBox(QMessageBox::Question,
        "This is the title",
        "This is the text",
        QMessageBox::Yes | QMessageBox::No, this);

// set the flags you want: here is the case when you want to keep the close button
msgBox.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);

msgBox.exec();

Upvotes: 4

Related Questions