
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
ThePathView element lays out model-provided items on a path.More...
| Since: | Qt 4.7 |
| Inherits: |
APathView displays data from models created from built-in QML elements likeListModel andXmlListModel, or custom model classes defined in C++ that inherit fromQAbstractListModel.
The view has amodel, which defines the data to be displayed, and adelegate, which defines how the data should be displayed. Thedelegate is instantiated for each item on thepath. The items may be flicked to move them along the path.
For example, if there is a simple list model defined in a fileContactModel.qml like this:
import QtQuick 1.0ListModel {ListElement {name:"Bill Jones"icon:"pics/qtlogo.png" }ListElement {name:"Jane Doe"icon:"pics/qtlogo.png" }ListElement {name:"John Smith"icon:"pics/qtlogo.png" }}
This data can be represented as aPathView, like this:
import QtQuick 1.0Rectangle {width:240;height:200Component {id:delegateColumn {id:wrapperImage {anchors.horizontalCenter:nameText.horizontalCenterwidth:64;height:64source:icon }Text {id:nameTexttext:namefont.pointSize:16color:wrapper.PathView.isCurrentItem ?"red" :"black" } } }PathView {anchors.fill:parentmodel:ContactModel {}delegate:delegatepath:Path {startX:120;startY:100PathQuad {x:120;y:25;controlX:260;controlY:75 }PathQuad {x:120;y:100;controlX: -20;controlY:75 } } }}
(Note the above example usesPathAttribute to scale and modify the opacity of the items as they rotate. This additional code can be seen in thePathAttribute documentation.)
PathView does not automatically handle keyboard navigation. This is because the keys to use for navigation will depend upon the shape of the path. Navigation can be added quite simply by settingfocus totrue and callingdecrementCurrentIndex() orincrementCurrentIndex(), for example to navigate using the left and right arrow keys:
PathView {// ...focus:trueKeys.onLeftPressed:decrementCurrentIndex()Keys.onRightPressed:incrementCurrentIndex()}
The path view itself is a focus scope (seethe focus documentation page for more details).
Delegates are instantiated as needed and may be destroyed at any time. State shouldnever be stored in a delegate.
PathView attaches a number of properties to the root item of the delegate, for examplePathView.isCurrentItem. In the following example, the root delegate item can access this attached property directly asPathView.isCurrentItem, while the childnameText object must refer to this property aswrapper.PathView.isCurrentItem.
Component {id:delegateColumn {id:wrapperImage {anchors.horizontalCenter:nameText.horizontalCenterwidth:64;height:64source:icon }Text {id:nameTexttext:namefont.pointSize:16color:wrapper.PathView.isCurrentItem ?"red" :"black" } } }
Note that views do not enableclip automatically. If the view is not clipped by another item or the screen, it will be necessary to setclip: true in order to have the out of view items clipped nicely.
See alsoPath andPathView example.
delegate :Component |
The delegate provides a template defining each item instantiated by the view. The index is exposed as an accessibleindex property. Properties of the model are also available depending upon the type ofData Model.
The number of elements in the delegate has a direct effect on the flicking performance of the view whenpathItemCount is specified. If at all possible, place functionality that is not needed for the normal display of the delegate in aLoader which can load additional elements when needed.
Note that thePathView will layout the items based on the size of the root item in the delegate.
Here is an example delegate:
This property holds the maximum distance from the path that initiate mouse dragging.
By default the path can only be dragged by clicking on an item. If dragMargin is greater than zero, a drag can be initiated by clicking within dragMargin pixels of the path.
This property holds the rate at which a flick will decelerate.
The default is 100.
This property holds whether the view is currently moving due to the user flicking the view.
highlight :Component |
This property holds the component to use as the highlight.
An instance of the highlight component will be created for each view. The geometry of the resultant component instance will be managed by the view so as to stay with the current item.
The below example demonstrates how to make a simple highlight. Note the use of thePathView.onPath attached property to ensure that the highlight is hidden when flicked away from the path.
See alsohighlightItem andhighlightRangeMode.
highlightItem :Item |
This property holds the move animation duration of the highlight delegate.
If thehighlightRangeMode is StrictlyEnforceRange then this property determines the speed that the items move along the path.
The default value for the duration is 300ms.
These properties set the preferred range of the highlight (current item) within the view. The preferred values must be in the range 0.0-1.0.
If highlightRangeMode is set toPathView.NoHighlightRange
If highlightRangeMode is set toPathView.ApplyRange the view will attempt to maintain the highlight within the range, however the highlight can move outside of the range at the ends of the path or due to a mouse interaction.
If highlightRangeMode is set toPathView.StrictlyEnforceRange the highlight will never move outside of the range. This means that the current item will change if a keyboard or mouse action would cause the highlight to move outside of the range.
Note that this is the correct way to influence where the current item ends up when the view moves. For example, if you want the currently selected item to be in the middle of the path, then set the highlight range to be 0.5,0.5 and highlightRangeMode toPathView.StrictlyEnforceRange. Then, when the path scrolls, the currently selected item will be the item at that position. This also applies to when the currently selected item changes - it will scroll to within the preferred highlight range. Furthermore, the behaviour of the current item index will occur whether or not a highlight exists.
The default value isPathView.StrictlyEnforceRange.
Note that a valid range requirespreferredHighlightEnd to be greater than or equal topreferredHighlightBegin.
model :model |
This property holds the model providing data for the view.
The model provides a set of data that is used to create the items for the view. For large or dynamic datasets the model is usually provided by a C++ model object. Models can also be created directly in QML, using theListModel element.
Note:changing the model will reset the offset andcurrentIndex to 0.
See alsoData Models.
This property holds whether the view is currently moving due to the user either dragging or flicking the view.
The offset specifies how far along the path the items are from their initial positions. This is a real number that ranges from 0.0 to the count of items in the model.
path :Path |
This property holds the path used to lay out the items. For more information see thePath documentation.
These properties set the preferred range of the highlight (current item) within the view. The preferred values must be in the range 0.0-1.0.
IfhighlightRangeMode is set toPathView.NoHighlightRange
IfhighlightRangeMode is set toPathView.ApplyRange the view will attempt to maintain the highlight within the range, however the highlight can move outside of the range at the ends of the path or due to a mouse interaction.
IfhighlightRangeMode is set toPathView.StrictlyEnforceRange the highlight will never move outside of the range. This means that the current item will change if a keyboard or mouse action would cause the highlight to move outside of the range.
Note that this is the correct way to influence where the current item ends up when the view moves. For example, if you want the currently selected item to be in the middle of the path, then set the highlight range to be 0.5,0.5 andhighlightRangeMode toPathView.StrictlyEnforceRange. Then, when the path scrolls, the currently selected item will be the item at that position. This also applies to when the currently selected item changes - it will scroll to within the preferred highlight range. Furthermore, the behaviour of the current item index will occur whether or not a highlight exists.
The default value isPathView.StrictlyEnforceRange.
Note that a valid range requirespreferredHighlightEnd to be greater than or equal to preferredHighlightBegin.
These properties set the preferred range of the highlight (current item) within the view. The preferred values must be in the range 0.0-1.0.
IfhighlightRangeMode is set toPathView.NoHighlightRange
IfhighlightRangeMode is set toPathView.ApplyRange the view will attempt to maintain the highlight within the range, however the highlight can move outside of the range at the ends of the path or due to a mouse interaction.
IfhighlightRangeMode is set toPathView.StrictlyEnforceRange the highlight will never move outside of the range. This means that the current item will change if a keyboard or mouse action would cause the highlight to move outside of the range.
Note that this is the correct way to influence where the current item ends up when the view moves. For example, if you want the currently selected item to be in the middle of the path, then set the highlight range to be 0.5,0.5 andhighlightRangeMode toPathView.StrictlyEnforceRange. Then, when the path scrolls, the currently selected item will be the item at that position. This also applies to when the currently selected item changes - it will scroll to within the preferred highlight range. Furthermore, the behaviour of the current item index will occur whether or not a highlight exists.
The default value isPathView.StrictlyEnforceRange.
Note that a valid range requires preferredHighlightEnd to be greater than or equal topreferredHighlightBegin.
This attached property is true if this delegate is the current item; otherwise false.
It is attached to each instance of the delegate.
This property may be used to adjust the appearance of the current item.
This attached property holds whether the item is currently on the path.
If apathItemCount has been set, it is possible that some items may be instantiated, but not considered to be currently on the path. Usually, these items would be set invisible, for example:
It is attached to each instance of the delegate.
PathView.view :PathView |
This attached property holds the view that manages this delegate instance.
It is attached to each instance of the delegate.
This handler is called when the view is flicked. A flick starts from the point that the mouse or touch is released, while still in motion.
This handler is called when the view stops moving due to user interaction. If a flick was generated, this handler will be triggered once the flick stops. If a flick was not generated, the handler will be triggered when the user stops dragging - i.e. a mouse or touch release.
Decrements the current index.
Note: methods should only be called after the Component has completed.
Increments the current index.
Note: methods should only be called after the Component has completed.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.