QMessageBox Change Icon

QMessageBox Change Icon

The QMessageBox class provides a modal dialog for informing the user or for asking the user a question and receiving an answer. QMessageBox supports four predefined message severity levels, or message types, which really only differ in the predefined icon they each show. Specify one of the four predefined message types by setting the icon property to one of the predefined icons. The following rules are guidelines:

QMessageBox_default_icon
We can modified QMessagebox icon by use either setIcon() for one of the standard icons, or setIconPixmap() for a custom icon. This is a method how to QMessageBox change icon example. From this QMessageBox change icon code, I use setIconPixmap() method with input a png icon file. This is a screenshoot from default QMessageBox window and QMessageBox change icon window :

QMessageBox change iconWe can change QMessageBox Icon with this simple code :

    QMessageBox mb("Show Messagebox",
    "QMessageBox with new Icon?",
    QMessageBox::NoIcon,
    QMessageBox::Yes | QMessageBox::Default,
    QMessageBox::No,
    QMessageBox::Cancel);

    QPixmap exportSuccess(":new/icon/New.png");
    mb.setIconPixmap(exportSuccess);
    mb.exec();

You can download the complete change QMessageBox Icon source code at here.

Source :
http://www.qtcentre.org/threads/3430-customize-the-Icon-QMessageBox

Add a Comment

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