Question

How is possible to display a QMessageBox::warning with the triangular exclamation mark symbol like the one following?

Yellow background triangular exclamation mark

I can't find any option in QMessageBox::warning, I only get the red circular symbol.

Was it helpful?

Solution

The triangular icon should be the default for the QMessageBox::warning dialog, while the red circular one is the default for the QMessageBox::critical dialog.

In my python code I use either

QMessageBox.warning(None,QString("..."),QString("...."))

or the more complex

msg = "..."
q = QMessageBox(QMessageBox.Warning, "...",  QString(msg))
q.setStandardButtons(QMessageBox.Ok);
i = QIcon()
i.addPixmap(QPixmap("..."), QIcon.Normal)
q.setWindowIcon(i)
q.exec_()

And both of them works well.

Eventually can you show the code you use to show the dialog ?

OTHER TIPS

You can use the QMessageBox.setIcon() function to configure which symbol you see when the dialog is displayed.

The predefined icon property types are listed here: https://doc.qt.io/qt-5/qmessagebox.html#severity-levels-and-the-icon-and-pixmap-properties

Here is my C++ example of a message box with the yellow triangle icon:

    QMessageBox msgWarning;
    msgWarning.setText("WARNING!\nRunning low on coffee.");
    msgWarning.setIcon(QMessageBox::Warning);
    msgWarning.setWindowTitle("Caution");
    msgWarning.exec();

And here is my C++ example of a message box with the red circle icon:

    QMessageBox msgError;
    msgError.setText("CRITICAL ERROR!\nThe McRib is no longer available!");
    msgError.setIcon(QMessageBox::Critical);
    msgError.setWindowTitle("Danger");
    msgError.exec();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top