Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QMessageBox warning yellow exclamation mark icon

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.

like image 943
linello Avatar asked Oct 15 '25 20:10

linello


1 Answers

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();
like image 163
JimmyJimJames Avatar answered Oct 17 '25 23:10

JimmyJimJames