edA-qa mort-ora-y
edA-qa mort-ora-y

Reputation: 31871

QMessageBox addButton() using standard icon/display

I'm trying to make our popup messages boxes have more appropriate text, rather than the generic "Ok", "Cancel", etc. However, I don't see an easy way to get the standard icons on the buttons.

For example, normally the QMessageBox::Save button has an icon with it. Instead I want the text to be "Save Part", but since this is still essentially a save operation it'd be nice to have the same icon.

I'd be happy to have this tied to the Role, as all my custom test buttons map to one of the standard roles. Is there any easy way to get the standard icons onto the custom buttons?

Upvotes: 1

Views: 5066

Answers (2)

Neox
Neox

Reputation: 2004

If you just want to change the text on the StandardButton but keep the standard icon you can do the following:

QMessageBox *box = new QMessageBox("title", "text", QMessageBox::NoIcon, QMessageBox::Save, QMessageBox::Close, QMessageBox::Open);
box->button(QMessageBox::Save)->setText("Save part");
box->show();

This will result in following: enter image description here

And the button will keep the same role

Upvotes: 5

jofel
jofel

Reputation: 3405

Add a button with QMessageBox::addButton to QMessageBox, then call the Button's setIcon with the icon returned by the QStyle::standardIcon you want.

Upvotes: 1

Related Questions