Qt Quick simple learning tutorial

Source: Internet
Author: User

Qt QuickIs the content to be introduced in this article, mainly to understandQt Quick.Qt Quick(Qt User Interface Creation Kit) is an advanced User Interface technology, which allows developers and designers to collaborate to create animated touch-based User interfaces and applications.Qt QuickIncluding QtDeclarative C ++ module,QML(Qt Meta-Object Language) and their integrationQtIn the Creator IDE. InQtBy using the QtDeclarativeC ++ module, the program can easilyQMLFile.

QML is a descriptive scripting language. The file format ends with. qml. The syntax format is very similar to CSS (refer to the example of stationery), but it also supports Programming Control in the javacript format. It combines the advantages of QtDesigner UI and QtScript. QtDesigner can design a. ui interface file, but does not support

Interaction with Qt native C ++ code. QtScript can interact with the native Qt code, but there is one drawback. it is inconvenient to create a graphical object inherited from QObject in the script, so you can only create a graphical object in Qt code, then access from QtScript. QML can be used in

Create graphical objects in the script, and support various graphic effects, as well as state machines, and facilitate interaction with C ++ code written by Qt.

You can use QDeclarativeView to load the Qt C ++ file, just like using UiLoader to load the. ui file.

After using Qt for UI, you must be familiar with QHBoxLayout, QVBoxLayout, and QGridLayout, the three most important and commonly used layout managers.
Use the following three layout managers in QML: Row, Column, Grid, and Anchor.

QMLThe Row Element in will arrange its child controls in the same Row without overlap. We can also use its spacing attribute to define the distance between child controls.

QMLThe Column element in will arrange its child controls in the same row without overlap. We can use its spacing attribute to define the distance between child controls.

The Grid element in QML will arrange its subcontrols evenly in a Grid without overlap. Each subcontrol is placed at the 0, 0) position of a Grid unit, that is, the upper left corner. The rows and columns attributes of the Grid define the number of rows and columns of the Grid. The default number of columns is 4. We can also use the spacing attribute of the Grid to define the distance between Grid units. Note that the horizontal and vertical spacing are the same.

Anchor

Each item can be considered as having seven hidden "anchor lines": left, horizontalCenter, right, top, verticalCenter, baseline, and bottom

Baseline refers to the line where the text is located. If the item has no text, baselinw is the same as top. In addition, the Anchor system provides margins and offsets. Margins refers to the space left between an item and the outside, while offsets can be laid out by using center anchor lines.

You can use QDeclarativeView to load the Qt C ++ file, just like using UiLoader to load the. ui file.

Item class is the most basic class of QML

Components are similar to macros, functions, classes, struct, and other functions in other programming languages, namely code reuse.

The component consists of a separate QML file name. The file name always starts with an uppercase letter. You can directly use this file name when using this component. Item is the most commonly used QML type. It is generally used as a container of other types and can be understood as the top parent class. Its function is similar to QWidget in QtGui.

MouseArea adds a mouse response area for the Item. You can listen to mouse events in the mouse activity area.

The onClicked line adds a processing behavior for the mouse click event.

Component syntax rules. If you define clicked () in Cell. qml, you should use onClicked () When referencing it in main. qml. Then, "when" determines when the State PropertyChanges is triggered, and specifies the attributes of which element will change.

Transitions is used to increase the animation effect.

"From" and "to" indicate the two state changes that the current animation acts on. The parameter names of "from" and "to" come from the "name" attribute in the State.

ParalleAnimation specifies that multiple animations occur in parallel. NumberAnimation is used for property changes of the qreal type, while ColorAnimation is used for color changes.

Summary:Qt QuickThe content of the simple learning tutorial has been introduced. I hope this article will help you!

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.