QT Chinese display (Qmessagebox, Qlineedit Right-click menu, etc.)

Source: Internet
Author: User

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.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.