how to use default icons with qt

gatoatigrado picture gatoatigrado · Mar 29, 2009 · Viewed 7.1k times · Source

I'm using only Qt (though PyQt) and I don't get icons when I call e.g. QMessageBox.warning(). Is there a way to use the platform's default icons? Currently I'm using the more complete QMessageBox constructor and calling setIconPixmap.

Answer

Giancarlo picture Giancarlo · Apr 20, 2009

http://doc.qt.io/qt-5/qmessagebox.html

from the above link:

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.

so you should use the QMessageBox constructor:

QMessageBox ( Icon icon, const QString & title, const QString & text, StandardButtons buttons = NoButton, QWidget * parent = 0, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint )

and you can use one of these icons:

http://doc.qt.io/qt-5/qmessagebox.html#Icon-enum

for example you can pass this parameter for icon: QMessageBox::Warning

HTH! greets