There is a lot of information to change Qmessagebox's OK to Chinese. But most of them are troublesome. This article provides an easy way to customize Qmessagebox buttons, including translating them into Chinese display. Qmessagebox maintains the button inside it, and the user can add or remove buttons using the AddButton () method and the RemoveButton () method. Each button has a role attribute (enum Qmessagebox::buttonrole) that identifies the purpose of the button. The list of role attributes is as follows:
Constant |
Value |
Description |
Qmessagebox::invalidrole |
-1 |
The button is invalid. |
Qmessagebox::acceptrole |
0 |
Clicking the button causes the dialog to be accepted (e.g. OK). |
Qmessagebox::rejectrole |
1 |
Clicking the button causes the dialog to be rejected (e.g. Cancel). |
Qmessagebox::D estructiverole |
2 |
Clicking the button causes a destructive change (e.g. for discarding changes) and closes the dialog. |
Qmessagebox::actionrole |
3 |
Clicking the button causes changes to the elements within the dialog. |
Qmessagebox::helprole |
4 |
The button can clicked to request help. |
Qmessagebox::yesrole |
5 |
The button is a "Yes"-like button. |
Qmessagebox::norole |
6 |
The button is a "No"-like button. |
Qmessagebox::applyrole |
8 |
The button applies current changes. |
Qmessagebox::resetrole |
7 |
The button resets the dialog ' s fields to default values. |
As a result, users can use the AddButton () and RemoveButton () methods, combined with role properties, to customize the button for the Qmessagebox. In addition, the user can obtain a "key" or "Key list" via the button () or the buttons () method. Qmessagebox also provides a complex constructor that is used to customize the message dialog box when it is created, and the constructor prototype is as follows: Qmessagebox::qmessagebox (icon icon, const QString & title , const QString & text, standardbuttons buttons = Nobutton, Qwidget * parent = 0, qt::windowflags f = Qt::D ialog | Qt::mswindowsfixedsizedialoghint) So we have a simple idea of turning the "OK" button into a "OK" button: using the button () method to get the Qabstractbutton key, and then using the The Qabstractbutton's SetText () method renames it as "OK", and the sample code is as follows:
wrrmsg = new Qmessagebox (Qmessagebox::noicon, title, MSG, Qmessagebox::ok, 0);
if (Null!=wrrmsg->button (Qmessagebox::ok))
Wrrmsg->button (Qmessagebox::ok)->settext ("OK");
Where title is the window title of type Qstring, MSG is the message content of qstring type, Qmessagebox () for specific information, see the related Help documentation for QT. http://blog.csdn.net/desert187/article/details/40302049
OK button in Qmessagebox change to Chinese "OK"