Qt Quick in Qt 5.1
Qt Quick 2.1 is new in Qt 5.1. This is a summary of improvements and new features introduced by the new import and new classes in Qt 5.1:
- New threaded render loop for Mac, Linux, and Embedded.
- New render loop for windows for smoother animations.
- New Window properties: activeFocusItem, minimumWidth, minimumHeight, maximumWidth, maximumHeight, visibility, contentOrientation, and opacity.
- New Screen attached properties: name, desktopAvailableWidth, desktopAvailableHeight, logicalPixelDensity
- New Grid properties: horizontalAlignment, verticalAlignment, and effectiveHorizontalAlignment.
- New TextEdit properties: selectByKeyboard and textDocument
- A Window declared inside another Window or Item will automatically be transient for (centered upon) the outer window.
- These types are now part of Qt QML:
- VisualDataModel - Encapsulates a model and a delegate
These types are kept due to compatibility reasons and are replaced by the Qt QML Models types.
In Qt 5.1, there are several new modules which extend Qt Quick functionalities.
- Qt Quick Dialogs - contains types for creating and interacting with system dialogs
- Qt Quick Controls - provides a set of reusable UI components
- Qt Quick Layouts - contains types that are used to arrange items in the user interface
The What's New in Qt 5.1 has more information about the Qt 5.1 release.
Qt Quick in Qt 5.0
The Qt Quick module is new in Qt 5. It provides the visual canvas and scenegraph back-end as well as the
QtQuick QML module for QML application development.
As of Qt 5, the Qt Quick module is based on an OpenGL scenegraph. Many of the classes in the Qt Quick module have been ported from the QtDeclarative module from Qt 4.8 to use the scenegraph architecture; these classes have been renamed to use a
QQuick* prefix. (See the Porting QML Applications to Qt 5 for porting information.)
The following classes provide the basic functionality for interacting with the QML visual canvas from C++:
- QQuickItem - the base visual QML type (replaces
- QQuickView - a convenience window for rendering a QML scene from a QML file (replaces
- QQuickWindow - a base window for displaying a QML scene
- QQuickPaintedItem - convenience for using the QPainter API with the scenegraph
- QQuickImageProvider - fetches custom images for use in QML applications (replaces
- QQuickTextureFactory - use with QQuickImageProvider::requestTexture()
Custom rendering can be performed on the scenegraph using the following new classes:
Qt 5.0 - QtQuick QML Module
QtQuick 2.0 QML module is a major update.
Below are the additions in
QtQuick 2.0. For a list of behavioral changes which may affect applications ported from
QtQuick 1.x, see the Porting QML Applications to Qt 5.
Visual types, Graphical Effects and Sprites
- New Canvas type for drawing. This provides an API similar to that of the HTML5 Canvas API, along with some additional features.
- Supports two render targets:
- Supports background thread rendering.
- Supports tiled canvas rendering.
- Supports most of the HTML5 context2d APIs.
- Supports two render targets:
- New layer.enabled property enables an item to be rendered into an offscreen cache for optimization.
- New contains() method returns whether an item contains a specified point.
- New anchors.alignWhenCentered property can force centered anchors to align on a whole pixel.
- New enabled property is available, which stops input event delivery and removes active focus.
- New ShaderEffect and ShaderEffectSource types enable GLSL shader programs to be integrated directly into QML code and applied to QML items and images. (This obsoletes the experimental Qt.labs.shaders module.)
- New SpriteSequence type renders animated sprites and can transition between animations. Each animation in a sequence is represented by the new Sprite type.
- New AnimatedSprite type for drawing single sprite animations.
Animations and Transitions
- New AnimationController type enables an animation to be manually driven by a progress value.
- New PathAnimation type animates an item along a Path.
- New PathInterpolator type provides updated attribute values for an item animating along a path. It can be used as an low-level alternative to PathAnimation.
- New PathArc type creates an arc-type path.
- New PathCurve type creates a catmull-rom curve path.
- New PathSvg type creates a path from a SVG string.
- Changes common to PathLine, PathQuad and PathCubic:
relativeYproperties define the start and end points of a path relative to its start.
- PathCubic only:
- PathQuad only:
- Changes common to Text, TextEdit and TextInput:
contentHeightproperties provide the dimensions of the textual content.
effectiveHorizontalAlignmentproperty provides the read-only actual horizontal alignment.
- Changes common to both TextEdit and TextInput:
- Text only:
Text.RightElideis now supported where text spans multiple lines.
- New linkColor property controls the color of linked text.
- New lineLaidOut signal is emitted for every line during the layout process to give the option of positioning and/or resizing lines as they are laid out.
- New fontSizeMode property allows text to be fitted to the item size.
- New minimumPixelSize and minimumPointSize properties can be used to specify a lower bound when auto-fitting.
- TextEdit only:
- New baseUrl property specified the base URL used to resolve relative URLs within the text.
- TextInput only:
- New wrapMode property sets the text wrapping mode.
- New horizontalAlignment and verticalAlignment properties.
- New length property provides the total number of text characters.
- New persistentSelection property enables the text selection to persist when the window loses focus.
- positionAt() method now takes a y parameter.
- New MultiPointTouchArea type processes multi-point touches and provides information on touch points including position, pressure and velocity. Touch point data is provided by the new TouchPoint type.
- New DropArea type provides more advanced drag and drop functionality.
- Wheel events are now supported; events are provided through the new WheelEvent type.
- New propagateComposedEvents property sets whether composed events are propagated to other mouse areas. If this property is true and the handlers of the clicked, doubleClicked or pressAndHold signals reject a mouse event, the event will be propagated to overlapping MouseArea items in the same area that are lower in the stacking order.
- New cursorShape property controls the cursor shape.
- New rebound property specifies the transition to be applied when a flickable snaps back to its bounds.
- New topMargin, bottomMargin, leftMargin, rightMargin allow extra margin space to be specified for a flickable. This can be used, for example, to implement pull-to-refresh functionality for a list.
- New originX and originY properties provide the top left position of the content item.
- New dragging, draggingHorizontally and draggingVertically properties provide information on whether a flickable is currently being dragged.
- New flick() method flicks the view with a specific velocity.
- New cancelFlick() method stops any current flicking movement.
Positioners (Row, Column, Grid, Flow types):
- Changes common to Row, Column, Grid and Flow:
movetransitions can access a new ViewTransition attached property (see the ViewTransition documentation for examples) and can now animate arbitrary item properties (instead of being restricted to animating an item's position).
effectiveLayoutDirectionproperty provides the read-only actual layout direction of a positioner.
- New Positioner type provides
isLastItemattached properties for items within positioners.
spacingproperties on positioners now use real numbers instead of integers.
- Grid only:
Models and Views
- Any delegate of a view that uses a QAbstractItemModel-derived model type can use the syntax
model.<role> = <newDataValue>to modify the data for a particular role. (Previously, the
model.<role>syntax was only available for reading, not writing to, a role value.)
- By default, roles can no longer change type during a model's lifetime. The new dynamicRoles property can be set to restore the original (less performant) behavior.
- Now has features to filter the items to be displayed in a view. This is supported by the new groups, filterOnGroup, items and persistedItems properties.
- Changes common to both ListView and GridView:
- New transition support for animating the adding, removing and moving of items in a ListView or GridView. See the ViewTransition documentation for details.
verticalLayoutDirectionproperty enables items to be laid out from bottom-to-top using the new
footerItemproperties provide access to the instantiated header and footer items.
cacheBufferproperty now has a non-zero default.
- Delegates in the cache buffer are now created asynchronously.
- Setting a
RightToLeftlayout now also reverses the
- If the model is changed after the component is completed, currentIndex is reset to 0.
- ListView only:
- New section.labelPositioning property can fix the current section label to the start of the view, and the next section label to the end of the view, to prevent labels from scrolling while section items are still in view.
highlightResizeSpeedhave been renamed to highlightMoveVelocity and highlightResizeVelocity.
- GridView only:
- New currentItem property holds the current item in the view.
- New maximumFlickVelocity property controls the maximum flick velocity of the view.
- New snapMode property controls the snap model when flicking between items
- If the model is changed after the component is completed, the offset and currentIndex are reset to 0.
- New positionViewAtIndex() function allows the view to be moved to display the specified index.
- New indexAt() and itemAt() functions return the index or item at a specified point in the view.
- New Accessible attached property for implementing accessibility features in QML applications.
- New asynchronous property allows components to be instantiated with lower chance of blocking. If source is used with asynchronous: true the component will be compiled in a background thread.
- New active property can delay instantiation of a Loader object's item.
- New setSource() method loads an object with specific initial property values, similar to Component::createObject().
- This type can now be used as a value source, and will also restore any previously set binding when its when clause becomes false.
Support for various math and geometry-related value types, including QVector2D, QVector3D, QVector4D, QMatrix4x4 and QQuaternion, as well as QColor and QFont, are now provided by Qt Quick. Properties of these types can be declared in QML documents via the property syntax where the type name is
Qt Quick also provides implementation for the various value type factory or utility functions of the
Qt object which return or operate on values of the above types. The functions are:
|color||Qt.rgba(), Qt.hsla(), Qt.tint(), Qt.lighter(), Qt.darker(), Qt.colorEqual()|
Qt 5.0 - Additional QML Modules
This new module provides particle system support for creating a variety of 2D particle systems. See the QtQuick.Particles documentation for comprehensive details.
This obsoletes the experimental
This new module contains the Window type for creating a basic window and the Screen type for accessing a screen's resolution and other details. See the QtQuick.Window documentation for comprehensive details.
This new module provides access to the SQL Local Storage API that was previously accessible from the QML Global Object. See the QtQuick.LocalStorage documentation for details.