QMessageBoxのOKボタンを中国語「OK」に変更

2458 ワード

QMessageBoxのOKを中国語に変更する資料がたくさんあります.しかし、多くは面倒です.本明細書では、QMessageBoxのボタンをカスタマイズするための簡単な方法を提供し、中国語表示に翻訳することを含む.
 
QMessageBoxは内部のButtonをメンテナンスし、ユーザーはaddButton()メソッドとremoveButton()メソッドを使用してボタンを追加または削除することができます.各Buttonには、そのButtonの用途を識別する役割属性(enum QMessageBox::ButtonRole)があります.
ロールのプロパティのリストは次のとおりです.
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::DestructiveRole
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 be 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.
したがって、ユーザは、addButton()メソッドとremoveButton()メソッドを使用して、キャラクタのプロパティと組み合わせて、QMesageBoxを定義するButtonから使用することができる.
また、ユーザはbutton()またはbuttons()メソッドにより「キー」または「キーリスト」を得ることができる.
QMessageBoxには、メッセージ・ダイアログ・ボックスの作成時にカスタマイズする複雑なコンストラクション関数も用意されています.コンストラクション関数のプロトタイプは次のとおりです.
 
QMessageBox::QMessageBox(Icon icon, const QString & title, const QString & text, StandardButtons buttons = NoButton, QWidget * parent = 0, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint)
 
そこで、「OK」キーを「OK」キーに変更する最も簡単な考え方を得た.button()メソッドを使用してQABstractButtonキーを取得し、QABstractButtonのsetText()メソッドを使用して「OK」と名前を変更した.サンプルコードは以下の通りである.
    WrrMsg = new QMessageBox(QMessageBox::NoIcon, title, msg, QMessageBox::Ok, 0);
    if(NULL!=WrrMsg->button(QMessageBox::Ok))
    {
        WrrMsg->button(QMessageBox::Ok)->setText("   ");
    }
ここで、titleはQStringタイプのウィンドウタイトルであり、msgはQStringタイプのメッセージ内容であり、QMessageBox()の詳細はQtの関連ヘルプドキュメントを参照してください.
 
http://blog.csdn.net/desert187/article/details/40302049