Source: http://blog.sina.com.cn/s/blog_a6fb6cc90101art3.html
In the time of writing QT program, always encounter Chinese problem, have been very confused, originally in use qlineedit when always appear right key English situation, beginning is the right button function to shield off. Use Setcontextmenupolicy (Qt::nocontextmenu) to set no right-click menu, but later found that although it is easy, but there are shortcomings, password box can not be right-click menu, not copy, paste, but ordinary text box still need this function, So it is easy to find out how to achieve it.
1. From the QT installation directory, copy the file "D:\SOFTWARE\QTOPENSOURCE\TRANSLATIONS\QT_ZH_CN.QM" to your project directory.
2. Establishment of resource files (QRC.QRC)
Location is under Engineering directory:
Content:
Qt_zh_cn.qm
3. Load the corresponding resource file in the main function main.cpp.
1#include #include"main_widget.h"2 3 intMainintargcChar*argv[])4 { 5 //Create Qapplication objects, manage resources for the entire application, and get its own command-line arguments through ARGC and argv;6 qapplication app (argc, argv);7 8 //set the encoding, generally in the window development environment, is the GBK encoding, in the Linux development environment, is the Utf-8 code9 //Gets the system code, otherwise the migration will appear garbledTenQtextcodec *codec = Qtextcodec::codecforname ("System"); One A //default encoding format for setting and reading and writing to the local file system - Qtextcodec::setcodecforlocale (codec); - the //sets the default string encoding when passed to the TR function - QTEXTCODEC::SETCODECFORTR (codec); - - //a coding method used to construct qstring objects using character constants or Qbytearray + qtextcodec::setcodecforcstrings (codec);
- //load the resource files in Qt to make QT display Chinese (including Qmessagebox, text box Right-click menu, etc.)
Qtranslator Translator; +Translator.load (":/QM/QT_ZH_CN"); AApp.installtranslator (&translator); at - Mainwidget Main_widget; - main_widget.show (); - - returnapp.exec (); -}
Note:Technology lies in communication, communication, reproduced please specify the source and maintain the integrity of the work.╰☆ struggle ing? Child ' Original: http://blog.sina.com.cn/s/blog_a6fb6cc90101art3.html.
QT Chinese display (Qmessagebox, Qlineedit Right-click menu, etc.)