View Full Version : Button icons in QMessageBox?

19th January 2010, 15:48

I'm trying to set an icon to the buttons of the QMessageBox (StandardButton enum), not the icon of the QMessageBox (QMessageBox::icon() ).

In my aplication the QPushButtons has an icon established by QtDesigner.
I'd like not to inherentance the QMessageBox because I'd like to use the static functions QMessageBox::critical(...) and so on. There're vey useful and a quick way to popup any info.

I tried by stylesheet, I have a qss that I load at the aplicattion starts up.
My best tries, has been:
dialog-cancel-icon: url../images/icons/Cerrar.png);
dialog-close-icon: url(../images/icons/Cerrar.png);
dialog-ok-icon: url(../images/icons/Ok.png);
dialog-yes-icon: url(../images/icons/Ok.png);
dialog-no-icon: url(../images/icons/Cerrar.png);
dialog-apply-icon: url(../images/icons/Ok.png);
dialog-reset-icon: url(../images/icons/Cerrar.png);

I've tried with "QDialog" instead of "QMessageBox", but nothing, no icon appear in the message box buttons.
The paths to the images are ok, because in another widgets works.

Is anyway to do this? How? Coding, stylesheets?

Thank you :)

19th January 2010, 15:54
you can use setDefaultButton() and other setXYZButton() functions of QMessagBox to set your own pushbuttons which already have the icons...

19th January 2010, 17:27
At last!
In Qt style sheets reference appears the next example:
QMessageBox {
dialogbuttonbox-buttons-have-icons: true;
dialog-ok-icon: url(ok.svg);
dialog-cancel-icon: url(cancel.png), url(grayed_cancel.png) disabled;

But It doesn't work, instead you have to set the same to QDialogButtonBox, ex:
dialogbuttonbox-buttons-have-icons: 1;
icon-size: 50px 50px;
dialog-ok-icon: url(ok.png);
dialog-cancel-icon: url(cerrar.png);

This have the disavantage that change all QDialogButtonBox, not only which are part of the QMessageBox, but the way:
QMessageBox QDialogButtonBox {
not work.

I have problems with the "icon-size" now, it doesn't work. In the help says to use this property to set the icon's size but... The only workaround that I found is to set QMessageBox's QPushButton icon-size, ex:
QMessageBox QPushButton
qproperty-iconSize: 50px 50px;

By the way, thank you MrDeath for your advice, but I don't understand how set the a standardbutton (for ex: Yes button), there isn't a setYesButton(). Only setDefaultButton() and setEscapeButton() in the QMessageBox API.