How to display icon in QMessageBox?

Nathan Osman picture Nathan Osman · Aug 21, 2010 · Viewed 9.2k times · Source

I have an about box that I'm trying to display an icon inside.

Here is my code:

QMessageBox about_box(this);

about_box.setText("...");
about_box.setIconPixmap(QPixmap("qrc:/images/logo.png"));
about_box.setParent(this);

about_box.exec();

Here is my resource file:

<RCC>
    <qresource prefix="/images">
        <file>logo.png</file>
    </qresource>
</RCC>

Answer

Ihor Kaharlichenko picture Ihor Kaharlichenko · Aug 21, 2010

You don't need the qrc prefix:

about_box.setIconPixmap(QPixmap(":/images/logo.png"));