How to translate the buttons in qmessagebox?

前端 未结 6 826
轮回少年
轮回少年 2020-12-30 01:43

I have a QMessageBox like this:

QMessageBox::question(this, tr(\"Sure want to quit?\"), 
    tr(\"Sure to quit?\"), QMessageBox::Yes | QMessageB         


        
6条回答
  •  攒了一身酷
    2020-12-30 02:40

    You can translate Text "Save" in this case to different language by clicking translatable check box as below.

    Which language is depending on the locale you load when loading the application. You can do this as follows

    QApplication app(argc, argv);
    //loading my_translation_pt file
    QString file= app.applicationDirPath() +"/my_translation_pt";
    QTranslator translator;
    translator.load(file);
    //Setting the translator to the QApp
    app.installTranslator(&translator);

    sample my_translation_pt file is attached below



    you can encode the tranlation using
    c:\Qt\4.7.1\bin>lrelease.exe :\temp\my_translation_pt

提交回复
热议问题