请问谁知道怎么把Qt中的QMessageBox中显示的ok和cancel改成汉字啊 确定和取消啊!

2024年11月30日 01:50
有2个网友回答
网友(1):

#include 
#include
#include
#include
int main(int argc,char *argv[])
{
    QApplication a(argc,argv);
                                                                                                                                                                                                                              
    QTextCodec::setCodecForTr(QTextCodec::codecForName("GB18030"));
                                                                                                                                                                                                                              
    QPushButton *okbtn=new QPushButton(QObject::tr("确定"));
    QPushButton *cancelbtn=new QPushButton(QObject::tr("取消"));
                                                                                                                                                                                                                              
    QMessageBox *mymsgbox=new QMessageBox;
                                                                                                                                                                                                                              
    mymsgbox->addButton(okbtn,QMessageBox::AcceptRole);
    mymsgbox->addButton(cancelbtn,QMessageBox::RejectRole);
                                                                                                                                                                                                                              
    mymsgbox->show();
    a.exec();
}
//代码不用解释了吧,你可以查看QT助手,主要是成员函数addButton的使用,很简单

上面是4.8的代码,如果你是在5.1的版本下,要防止汉子变乱码,一种方法是源代码以无BOM格式保存,另一种是用QTextCodec类,QT助手有使用方法

网友(2):

1、QT的国际化可以自动翻译的。
2、自己做个Box