PDA

View Full Version : Getting the Icon of a MessageBox



thru
29th December 2010, 16:45
Hi,

Does anyone know if it's possible getting the Icon that would be shown in a QMessageBox? (the idea is to use the qt's internal icon that you would get in a QMessage box with for example QMessageBox::Warning)

thanks!

javimoya
29th December 2010, 16:55
QIcon QStyle::standardIcon ( StandardPixmap standardIcon, const QStyleOption * option = 0, const QWidget * widget = 0 )

standardIcon = QStyle::SP_MessageBoxWarning


-------

you can see internally how qmessagebox get his icon here:

QPixmap QMessageBoxPrivate::standardIcon(QMessageBox::Icon icon, QMessageBox *mb)
{
QStyle *style = mb ? mb->style() : QApplication::style();
int iconSize = style->pixelMetric(QStyle::PM_MessageBoxIconSize, 0, mb);
QIcon tmpIcon;
switch (icon) {
case QMessageBox::Information:
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxInformation, 0, mb);
break;
case QMessageBox::Warning:
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxWarning, 0, mb);
break;
case QMessageBox::Critical:
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxCritical, 0, mb);
break;
case QMessageBox::Question:
tmpIcon = style->standardIcon(QStyle::SP_MessageBoxQuestion, 0, mb);
default:
break;
}
if (!tmpIcon.isNull())
return tmpIcon.pixmap(iconSize, iconSize);
return QPixmap();
}

thru
29th December 2010, 17:19
It works, thanks!!