Qt implements split windows and Internationalization

Source: Internet
Author: User

Original works of Li Wanpeng, majoring in software engineering, Harbin Institute of Technology

Http://blog.csdn.net/woshixingaaa/archive/2010/08/10/5802312.aspx

The qsqlitter class is provided in QT to implement split windows. Split windows can flexibly distribute window la S, which are often used in window design similar to file manager. Qt provides the qtranslator class and qlinguist tool for internationalization. This example implements a split window and internationalization.

After Internationalization

Create a qslitter object. First, create a horizontal main split window (QT: horizontal), and then create a right split window (QT: vertical ), then, three qtextedit objects are loaded into each window. The setalignment () method is used to set the alignment of text in qtextedit.

Qt: alignleft: left aligned

Qt: alignright: Right-aligned

Qt: aligncenter: Text Center

Qt: alignup: Align text with top

Qt: alignbottom: Align text with bottom

Setopaqueresize (bool) is used to set whether the display is updated in real time when the split window is moved. If it is set to true, the display is updated in real time, if it is set to false, only one gray line is displayed when you drag the image. The setstretchfactor () method is used to set a Scalable Control. Its first parameter specifies the serial number of the control set. The serial number of the control is numbered from 0 in the order of insertion, the second parameter is greater than 0, indicating that the control is a Scalable Control. When the width of the entire dialog box changes, the width of the left text editing box remains unchanged, the width of the Right Split box varies with the size of the entire dialog box.

# Include <qapplication> <br/> # include <qsplitter> <br/> # include <qtextedit> <br/> # include <qtranslator> <br/> int main (int argc, char * argv []) {<br/> qapplication app (argc, argv); <br/> qtranslator qttranslator; <br/> qttranslator. load ("9.qm"); <br/> app. installtranslator (& qttranslator); <br/> qsplitter * mainsplitter = new qsplitter (QT: horizontal, 0); <br/> qtextedit * e1 = new qtextedit (qobject :: TR ("Left window"), mainsplitter); <br/> E1-> setalignment (QT: aligncenter); <br/> qsplitter * rightsplitter = new qsplitter (QT :: vertical, mainsplitter); <br/> rightsplitter-> setopaqueresize (false); <br/> qtextedit * e2 = new qtextedit (qobject: TR ("Top Window "), rightsplitter); <br/> E2-> setalignment (QT: aligncenter); <br/> qtextedit * E3 = new qtextedit (qobject: TR ("bottom window "), rightsplitter); <br/> E3-> setalignment (QT: aligncenter); <br/> mainsplitter-> setstretchfactor (1, 1 ); <br/> mainsplitter-> show (); <br/> return app.exe C (); <br/>}

Next we will start internationalization. The so-called internationalization not only translates various texts on the interface into other languages, but also converts writing methods and currencies. For example, Arabic writing from right to left must be completed in internationalization.

First, we need to add a line in pro

Translations + = MyApp. Ts

 

MyApp. Ts is the translation file to be created. This name is arbitrary, but the suffix name Is ts. Then, open the command prompt, enter the project directory, that is, my directory QT/9, and then enter

Lupdate 9.pro

If the following results are displayed, the TS file is successfully created.

The last line indicates that three files need to be translated, and zero files already exist. That is to say, this file is newly created. You can find this ts file in the project and open it in Notepad. This file is actually an XML file. We use professional tools linguist to open ts files.

Then, complete the translation and save it. Then there is a release under the menu, click it, and there will be a MyApp under the project folder. QM file, which is the file we have translated. qt's QM file is in binary format, so it is highly optimized and small in size. Let's take a look at this Code:

Qtranslator qttranslator; <br/> qttranslator. Load ("MyApp. QM"); <br/> app. installtranslator (& qttranslator );

First create a qtranslator object, then load the Qm file, that is, the binary file we obtained after the translation, then install the object into the qapplication, and re-compile it. So far, if you feel better, please encourage the following, it is not easy.

Related Article

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.