QML ListView Element

来源:互联网 发布:淘宝买的steam游戏礼物 编辑:程序博客网 时间:2024/05/06 09:52

QML ListView Element

The ListView item provides a list view of items provided by a model. More...

ListView项展示了由model提供的项的列表视图。

Inherits Flickable

  • List of all members, including inherited members

Properties

  • cacheBuffer : int
  • count : int
  • currentIndex : int
  • currentItem : Item
  • currentSection : string
  • delegate : Component
  • footer : Component
  • header : Component
  • highlight : Component
  • highlightFollowsCurrentItem : bool
  • highlightItem : Item
  • highlightMoveDuration : int
  • highlightMoveSpeed : real
  • highlightRangeMode : enumeration
  • highlightResizeDuration : int
  • highlightResizeSpeed : real
  • keyNavigationWraps : bool
  • model : model
  • orientation : enumeration
  • preferredHighlightBegin : real
  • preferredHighlightEnd : real
  • section.criteria : enumeration
  • section.delegate : Component
  • section.property : string
  • snapMode : enumeration
  • spacing : real

Attached Properties

  • delayRemove : bool
  • isCurrentItem : bool
  • nextSection : string
  • previousSection : string
  • section : string
  • view : ListView

Attached Signals

  • onAdd
  • onRemove

Methods

  • decrementCurrentIndex
  • incrementCurrentIndex
  • indexAt
  • positionViewAtIndex

Detailed Description

A ListView displays data from models created from built-in QML elements like ListModel and XmlListModel, or custom model classes defined in C++ that inherit from QAbstractListModel.

ListView显示model的数据,这些model可以从内建的QML元素ListModel和XmlListModel创建,或者用继承于QAbstractListModel的自定义C++ model类。

A ListView has a model, which defines the data to be displayed, and a delegate, which defines how the data should be displayed. Items in a ListView are laid out horizontally or vertically. List views are inherently flickable because ListView inherits from Flickable.

一个ListView有一个model和一个delegate,model定义了要被显示的数据,delegate定义了如何显示数据。ListView上Items布局为horizontally 或vertically。因为ListView继承自Flickable,所以列表视图天生flickable。

Example Usage

The following example shows the definition of a simple list model defined in a file called ContactModel.qml:

下面的例子显示了定义在ContactModel.qml文件中的简单的list model:

[javascript] view plaincopyprint?
  1. import QtQuick 1.0  
  2.   
  3. ListModel {  
  4.     ListElement {  
  5.         name: "Bill Smith"  
  6.         number: "555 3264"  
  7.     }  
  8.     ListElement {  
  9.         name: "John Brown"  
  10.         number: "555 8426"  
  11.     }  
  12.     ListElement {  
  13.         name: "Sam Wise"  
  14.         number: "555 0473"  
  15.     }  
  16. }  

 


Another component can display this model data in a ListView, like this:

另一个组件能显示ListView里的model数据,

[javascript] view plaincopyprint?
  1. import QtQuick 1.0  
  2.   
  3.  ListView {  
  4.      width: 180; height: 200  
  5.   
  6.      model: ContactModel {}  
  7.      delegate: Text {  
  8.          text: name + ": " + number  
  9.      }  
  10.  }  
[javascript] view plaincopyprint?
  1. <IMG style="BORDER-RIGHT-WIDTH: 0px; MAX-WIDTH: 100%; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" alt="" src="http://write.blog.csdn.net/images/listview-simple.png">  

Here, the ListView creates a ContactModel component for its model, and a Text element for its delegate. The view will create a new Text component for each item in the model. Notice the delegate is able to access the model's name and number data directly.

这里,ListView创建一个ContactModel 组件作为它自己的model,一个Text元素作为它自己的delegate。这视图会为model中的每个item创建一个新的Text组件。注意,delegate能直接访问model的name和number数据。

An improved list view is shown below. The delegate is visually improved and is moved into a separate contactDelegate component.

下面显示了改进的列表视图。这个delegate提高了可视化,移到了独立的contactDelegate 组件。

[javascript] view plaincopyprint?
  1. Rectangle {  
  2.      width: 180; height: 200  
  3.   
  4.      Component {  
  5.          id: contactDelegate  
  6.          Item {  
  7.              width: 180; height: 40  
  8.              Column {  
  9.                  Text { text: '<b>Name:</b> ' + name }  
  10.                  Text { text: '<b>Number:</b> ' + number }  
  11.              }  
  12.          }  
  13.      }  
  14.   
  15.      ListView {  
  16.          anchors.fill: parent  
  17.          model: ContactModel {}  
  18.          delegate: contactDelegate  
  19.          highlight: Rectangle { color: "lightsteelblue"; radius: 5 }  
  20.          focus: true  
  21.      }  
  22.  }  
<img style="BORDER-RIGHT-WIDTH: 0px; MAX-WIDTH: 100%; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" alt="" src="http://write.blog.csdn.net/images/listview-highlight.png" />

 

The currently selected item is highlighted with a blue Rectangle using the highlight property, and focus is set to true to enable keyboard navigation for the list view. The list view itself is a focus scope (see the focus documentation page for more details).

使用highlight属性使得当前选择项为高亮的蓝色矩形框,focus被设置为true可使得列表能通过键盘来导航。列表视图自己就是焦点区域。

Delegates are instantiated as needed and may be destroyed at any time. State should never be stored in a delegate.

delegate可以在任何时候需要的时候被实例化和析构。永远(never)不要在在delegate中存储State。

ListView attaches a number of properties to the root item of the delegate, for example ListView.isCurrentItem. In the following example, the root delegate item can access this attached property directly as ListView.isCurrentItem, while the child contactInfo object must refer to this property aswrapper.ListView.isCurrentItem.

ListView附加了许多属性给delegate的根项,例如,ListView.isCurrentItem。下面的例子中,delegate的根项可以直接访问这个附加属性如,ListView.isCurrentItem,而它的子对象contactInfo必须按wrapper.ListView.isCurrentItem这样引用这个属性。

 

<div class="dp-highlighter bg_javascript"><div class="bar"><div class="tools"><strong>[javascript]</strong> <a target=_blank class="ViewSource" title="view plain" href="http://blog.csdn.net/jokerjhm/article/details/6736502#">view plain</a><a target=_blank class="CopyToClipboard" title="copy" href="http://blog.csdn.net/jokerjhm/article/details/6736502#">copy</a><a target=_blank class="PrintSource" title="print" href="http://blog.csdn.net/jokerjhm/article/details/6736502#">print</a><a target=_blank class="About" title="?" href="http://blog.csdn.net/jokerjhm/article/details/6736502#">?</a></div></div><ol class="dp-c"><li class="alt"><span><span>ListView {  </span></span></li><li><span>    width: 180; height: 200  </span></li><li class="alt"><span>  </span></li><li><span>    Component {  </span></li><li class="alt"><span>        id: contactsDelegate  </span></li><li><span>        Rectangle {  </span></li><li class="alt"><span>            id: wrapper  </span></li><li><span>            width: 180  </span></li><li class="alt"><span>            height: contactInfo.height  </span></li><li><span>            color: ListView.isCurrentItem ? </span><span class="string">"black"</span><span> : </span><span class="string">"red"</span><span>  </span></li><li class="alt"><span>            Text {  </span></li><li><span>                id: contactInfo  </span></li><li class="alt"><span>                text: name + </span><span class="string">": "</span><span> + number  </span></li><li><span>                color: wrapper.ListView.isCurrentItem ? </span><span class="string">"red"</span><span> : </span><span class="string">"black"</span><span>  </span></li><li class="alt"><span>            }  </span></li><li><span>        }  </span></li><li class="alt"><span>    }  </span></li><li><span>  </span></li><li class="alt"><span>    model: ContactModel {}  </span></li><li><span>    delegate: contactsDelegate  </span></li><li class="alt"><span>    focus: </span><span class="keyword">true</span><span>  </span></li><li><span>}  </span></li></ol></div><pre style="DISPLAY: none" class="javascript" name="code"> ListView {     width: 180; height: 200     Component {         id: contactsDelegate         Rectangle {             id: wrapper             width: 180             height: contactInfo.height             color: ListView.isCurrentItem ? "black" : "red"             Text {                 id: contactInfo                 text: name + ": " + number                 color: wrapper.ListView.isCurrentItem ? "red" : "black"             }         }     }     model: ContactModel {}     delegate: contactsDelegate     focus: true }

Note: Views do not enable clip automatically. If the view is not clipped by another item or the screen, it will be necessary to set clip: true in order to have the out of view items clipped nicely.

注意:Views不能自动clip。如果这个view不能被另一项或屏幕clip,它必须设置clip:true,为了使得视图项外能被更好的clip。

See also QML Data Models, GridView, and ListView examples.

Property Documentation

cacheBuffer : int

This property determines whether delegates are retained outside the visible area of the view.

If this value is non-zero, the view keeps as many delegates instantiated as it can fit within the buffer specified. For example, if in a vertical view the delegate is 20 pixels high and cacheBuffer is set to 40, then up to 2 delegates above and 2 delegates below the visible area may be retained.

Note that cacheBuffer is not a pixel buffer - it only maintains additional instantiated delegates.

Setting this value can improve the smoothness of scrolling behavior at the expense of additional memory usage. It is not a substitute for creating efficient delegates; the fewer elements in a delegate, the faster a view can be scrolled.


read-onlycount : int

This property holds the number of items in the view.

这个属性持有view中item的数目


currentIndex : int

currentItem : Item

The currentIndex property holds the index of the current item, and currentItem holds the current item. Setting the currentIndex to -1 will clear the highlight and set currentItem to null.

属性currentIndex 持有当前项的索引,属性currentItem 持有当前项。设置当前索引为-1将清除高亮并将currentItem设置为null。

If highlightFollowsCurrentItem is true, setting either of these properties will smoothly scroll the ListView so that the current item becomes visible.

如果highlightFollowsCurrentItem为真,设置任一个属性都会平滑滚动ListView使得当前项变为可见。

Note that the position of the current item may only be approximate until it becomes visible in the view.

注意当前项的位置可以是大致的直到它变的可见。


read-onlycurrentSection : string

This property holds the section that is currently at the beginning of the view.

这个属性持有视图开始部分的当前分段。


delegate : Component

The delegate provides a template defining each item instantiated by the view. The index is exposed as an accessible index property. Properties of the model are also available depending upon the type of Data Model.

delegate提供了一个模板来定义被view实例化的每项。索引被暴露作为可访问的属性index。model的属性的可用性也可依赖Data Model的类型。

The number of elements in the delegate has a direct effect on the flicking performance of the view. If at all possible, place functionality that is not needed for the normal display of the delegate in a Loader which can load additional elements when needed.

delegate中的元素的数目会直接影响视图的flicking性能。如果可能,把不需要为delegate正常显示的功能放进Loader里,Loader能只有需要时加载额外元素。

The ListView will lay out the items based on the size of the root item in the delegate.

ListView会基于delegate根项的大小来布局items。

It is recommended that the delagate's size be a whole number to avoid sub-pixel alignment of items.

建议delagate的大小是一个整数来避免项的亚像素校准。

Note: Delegates are instantiated as needed and may be destroyed at any time. State should never be stored in a delegate.

注意:delegate可以在任何需要的时候被实例化和析构。State永远不要存储在delegate中。

 


footer : Component

This property holds the component to use as the footer.

这个属性持有作为footer的组件。

An instance of the footer component is created for each view. The footer is positioned at the end of the view, after any items.

每个view创建一个footer组件的实例。位于view的结尾,任何item的后面。

See also header.


header : Component

This property holds the component to use as the header.

这个属性持有作为header的组件。

An instance of the header component is created for each view. The header is positioned at the beginning of the view, before any items.

每个view创建一个header 组件的实例。位于view的开头,任何item的前面。

 

See also footer.


highlight : Component

This property holds the component to use as the highlight.

这个属性持有用作高亮的组件。

An instance of the highlight component is created for each list. The geometry of the resulting component instance is managed by the list so as to stay with the current item, unless the highlightFollowsCurrentItem property is false.

每个列表创建一个高亮组件的实例。最终产生的组件实例的几何由列表来管理以致能保留在当前项,除非highlightFollowsCurrentItem为false。

See also highlightItem, highlightFollowsCurrentItem, and ListView examples.


highlightFollowsCurrentItem : bool

This property holds whether the highlight is managed by the view.

这属性持有高亮是否由视图来管理。

If this property is true (the default value), the highlight is moved smoothly to follow the current item. Otherwise, the highlight is not moved by the view, and any movement must be implemented by the highlight.

如果这个属性为true(默认值),这个高亮随着当前项平滑的移动。否则,高亮不会被视图移动,任何移动必须由高亮来实现。

Here is a highlight with its motion defined by a SpringAnimation item:

这里有个高亮,它的动作定义在SpringAnimation项。

 <div class="dp-highlighter bg_javascript"><div class="bar"><div class="tools"><strong>[javascript]</strong> <a target=_blank class="ViewSource" title="view plain" href="http://blog.csdn.net/jokerjhm/article/details/6736502#">view plain</a><a target=_blank class="CopyToClipboard" title="copy" href="http://blog.csdn.net/jokerjhm/article/details/6736502#">copy</a><a target=_blank class="PrintSource" title="print" href="http://blog.csdn.net/jokerjhm/article/details/6736502#">print</a><a target=_blank class="About" title="?" href="http://blog.csdn.net/jokerjhm/article/details/6736502#">?</a></div></div><ol class="dp-c"><li class="alt"><span><span>Component {  </span></span></li><li><span>    id: highlight  </span></li><li class="alt"><span>    Rectangle {  </span></li><li><span>        width: 180; height: 40  </span></li><li class="alt"><span>        color: </span><span class="string">"lightsteelblue"</span><span>; radius: 5  </span></li><li><span>        y: list.currentItem.y  </span></li><li class="alt"><span>        Behavior on y {  </span></li><li><span>            SpringAnimation {  </span></li><li class="alt"><span>                spring: 3  </span></li><li><span>                damping: 0.2  </span></li><li class="alt"><span>            }  </span></li><li><span>        }  </span></li><li class="alt"><span>    }  </span></li><li><span>}  </span></li><li class="alt"><span>  </span></li><li><span>ListView {  </span></li><li class="alt"><span>    id: list  </span></li><li><span>    width: 180; height: 200  </span></li><li class="alt"><span>    model: ContactModel {}  </span></li><li><span>    delegate: Text { text: name }  </span></li><li class="alt"><span>  </span></li><li><span>    highlight: highlight  </span></li><li class="alt"><span>    highlightFollowsCurrentItem: </span><span class="keyword">false</span><span>  </span></li><li><span>    focus: </span><span class="keyword">true</span><span>  </span></li><li class="alt"><span>}  </span></li></ol></div><pre style="DISPLAY: none" class="javascript" name="code"> Component {     id: highlight     Rectangle {         width: 180; height: 40         color: "lightsteelblue"; radius: 5         y: list.currentItem.y         Behavior on y {             SpringAnimation {                 spring: 3                 damping: 0.2             }         }     } } ListView {     id: list     width: 180; height: 200     model: ContactModel {}     delegate: Text { text: name }     highlight: highlight     highlightFollowsCurrentItem: false     focus: true }


Note that the highlight animation also affects the way that the view is scrolled. This is because the view moves to maintain the highlight within the preferred highlight range (or visible viewport).

注意高亮的动画对于视频滚动也是有效的。这是因为视图移动来维护高亮在优先高亮的范围(或可视范围)。

See also highlight and highlightMoveSpeed.


read-onlyhighlightItem : Item

This holds the highlight item created from the highlight component.

这持有hightlight组件创建的高亮项。

The highlightItem is managed by the view unless highlightFollowsCurrentItem is set to false.

highlightItem 由视图管理,除非highlightFollowsCurrentItem为false。

See also highlight and highlightFollowsCurrentItem.


highlightMoveSpeed : real

highlightMoveDuration : int

highlightResizeSpeed : real

highlightResizeDuration : int

These properties hold the move and resize animation speed of the highlight delegate.

highlightFollowsCurrentItem must be true for these properties to have effect.

The default value for the speed properties is 400 pixels/second. The default value for the duration properties is -1, i.e. the highlight will take as much time as necessary to move at the set speed.

These properties have the same characteristics as a SmoothedAnimation.

See also highlightFollowsCurrentItem.


keyNavigationWraps : bool

This property holds whether the list wraps key navigation.

这属性持有列表是否可循环键导航。

If this is true, key navigation that would move the current item selection past the end of the list instead wraps around and moves the selection to the start of the list, and vice-versa.

如果为true,键导航会从最后一项移到第一项。

By default, key navigation is not wrapped.

默认是不循环的。


model : model

This property holds the model providing data for the list.

这个属性持有给这个list提供数据的model。

The model provides the set of data that is used to create the items in the view. Models can be created directly in QML using ListModel, XmlListModel orVisualItemModel, or provided by C++ model classes. If a C++ model class is used, it must be a subclass of QAbstractItemModel or a simple list.

model提供数据集用于创建这个view里的item。model能直接被QML用 ListModel, XmlListModel 或VisualItemModel创建,或由C++model类提供。如果使用C++model类,它必须是QAbstractItemModel的子类,或简单的list。

See also Data Models.


orientation : enumeration

This property holds the orientation of the list.

Possible values:

  • ListView.Horizontal - Items are laid out horizontally
  • ListView.Vertical (default) - Items are laid out vertically
Horizontal orientation:

Vertical orientation:


preferredHighlightBegin : real

preferredHighlightEnd : real

highlightRangeMode : enumeration

These properties define the preferred range of the highlight (for the current item) within the view. The preferredHighlightBegin value must be less than thepreferredHighlightEnd value.

These properties affect the position of the current item when the list is scrolled. For example, if the currently selected item should stay in the middle of the list when the view is scrolled, set the preferredHighlightBegin and preferredHighlightEnd values to the top and bottom coordinates of where the middle item would be. If the currentItem is changed programmatically, the list will automatically scroll so that the current item is in the middle of the view. Furthermore, the behavior of the current item index will occur whether or not a highlight exists.

Valid values for highlightRangeMode are:

  • ListView.ApplyRange - the view attempts to maintain the highlight within the range. However, the highlight can move outside of the range at the ends of the list or due to mouse interaction.
  • ListView.StrictlyEnforceRange - the highlight never moves outside of the range. The current item changes if a keyboard or mouse action would cause the highlight to move outside of the range.
  • ListView.NoHighlightRange - this is the default value.

section.property : string

section.criteria : enumeration

section.delegate : Component

These properties hold the expression to be evaluated for the section attached property.

这些属性持有评估section附加属性的表达式。

The section attached property enables a ListView to be visually separated into different parts. These properties determine how sections are created.

section附加属性确保ListView被可视化的分为不同的部分。这些属性决定了分段是如何被创建的。

section.property holds the name of the property that is the basis of each section.

section.property持有属性的名称,它是每个分段的基础。

section.criteria holds the criteria for forming each section based on section.property. This value can be one of:

section.criteria持有每个基于section.property的分段格式的标准。这个值可能是:

  • ViewSection.FullString (default) - sections are created based on the section.property value.
  • ViewSection.FullString (default) -分段基于section.property 的值来创建
  • ViewSection.FirstCharacter - sections are created based on the first character of the section.property value (for example, 'A', 'B', 'C' sections, etc. for an address book)
  • ViewSection.FirstCharacter -分段是基于section.property的第一字符来创建的。(例如'A', 'B', 'C' 分段, 等等。用作地址本)

section.delegate holds the delegate component for each section.

section.delegate持有每个分段的delegate组件。

Each item in the list has attached properties named ListView.section, ListView.previousSection and ListView.nextSection. These may be used to place a section header for related items.

列表中的每项有附加属性: ListView.section, ListView.previousSection ListView.nextSection。这些属性可用于为相关的项放置分段的头。

For example, here is a ListView that displays a list of animals, separated into sections. Each item in the ListView is placed in a different section depending on the "size" property of the model item. The sectionHeading delegate component provides the light blue bar that marks the beginning of each section.

例如,这里有一个列表,它显示了一个animal列表,分为几段。列表视图里的每项依靠model项中“size”属性放在不同的分段里。sectionHeading delegate组件提供蓝色栏来标记每段的开始。

 <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-rectangle.html">Rectangle</a></span> {     <span style="color:black;">id</span>: <span style="color:black;">container</span>     <span style="color:black;">width</span>: <span>200</span>     <span style="color:black;">height</span>: <span>250</span>     <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-listmodel.html">ListModel</a></span> {         <span style="color:black;">id</span>: <span style="color:black;">animalsModel</span>         <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-listelement.html">ListElement</a></span> { <span style="color:black;">name</span>: <span>"Parrot"</span>; <span style="color:black;">size</span>: <span>"Small"</span> }         <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-listelement.html">ListElement</a></span> { <span style="color:black;">name</span>: <span>"Guinea pig"</span>; <span style="color:black;">size</span>: <span>"Small"</span> }         <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-listelement.html">ListElement</a></span> { <span style="color:black;">name</span>: <span>"Dog"</span>; <span style="color:black;">size</span>: <span>"Medium"</span> }         <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-listelement.html">ListElement</a></span> { <span style="color:black;">name</span>: <span>"Cat"</span>; <span style="color:black;">size</span>: <span>"Medium"</span> }         <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-listelement.html">ListElement</a></span> { <span style="color:black;">name</span>: <span>"Elephant"</span>; <span style="color:black;">size</span>: <span>"Large"</span> }     }     <span>// The delegate for each section header</span>     <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-component.html">Component</a></span> {         <span style="color:black;">id</span>: <span style="color:black;">sectionHeading</span>         <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-rectangle.html">Rectangle</a></span> {             <span style="color:black;">width</span>: <span style="color:black;">container</span>.<span style="color:black;">width</span>             <span style="color:black;">height</span>: <span style="color:black;">childrenRect</span>.<span style="color:black;">height</span>             <span style="color:black;">color</span>: <span>"lightsteelblue"</span>             <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(0,115,47); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-text.html">Text</a></span> {                 <span style="color:black;">text</span>: <span style="color:black;">section</span>                 <span style="color:black;">font</span>.bold: <span>true</span>             }         }     }     <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-listview.html">ListView</a></span> {         <span style="color:black;">anchors</span>.fill: <span style="color:black;">parent</span>         <span style="color:black;">model</span>: <span style="color:black;">animalsModel</span>         <span style="color:black;">delegate</span>: <span style="color:black;">Text</span> { <span style="color:black;">text</span>: <span style="color:black;">name</span> }         <span style="color:black;">section</span>.property: <span>"size"</span>         <span style="color:black;">section</span>.criteria: <span style="color:black;">ViewSection</span>.<span style="color:black;">FullString</span>         <span style="color:black;">section</span>.delegate: <span style="color:black;">sectionHeading</span>     } }

See also ListView examples.


snapMode : enumeration

This property determines how the view scrolling will settle following a drag or flick. The possible values are:

  • ListView.NoSnap (default) - the view stops anywhere within the visible area.
  • ListView.SnapToItem - the view settles with an item aligned with the start of the view.
  • ListView.SnapOneItem - the view settles no more than one item away from the first visible item at the time the mouse button is released. This mode is particularly useful for moving one page at a time.

snapMode does not affect the currentIndex. To update the currentIndex as the list is moved, set highlightRangeMode to ListView.StrictlyEnforceRange.

See also highlightRangeMode.


spacing : real

This property holds the spacing between items.

The default value is 0.


Attached Property Documentation

read-onlyListView.delayRemove : bool

This attached property holds whether the delegate may be destroyed.

这个附加属性持有这个delegate是否可以被销毁。

It is attached to each instance of the delegate.

它被附属到每个delegate的实例。

It is sometimes necessary to delay the destruction of an item until an animation completes.

有时候是必须延迟析构项的直到一个动画的完成。

The example delegate below ensures that the animation completes before the item is removed from the list.

下面的delegate例子确保了列表里的项目不会在动画完成之前被移除。

 <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-component.html">Component</a></span> {     <span style="color:black;">id</span>: <span style="color:black;">delegate</span>     <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-item.html">Item</a></span> {         <span style="color:black;">ListView</span>.onRemove: <span style="color:black;">SequentialAnimation</span> {             <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(0,115,47); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-propertyaction.html">PropertyAction</a></span> { <span style="color:black;">target</span>: <span style="color:black;">wrapper</span>; <span style="color:black;">property</span>: <span>"ListView.delayRemove"</span>; <span style="color:black;">value</span>: <span>true</span> }             <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(0,115,47); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-numberanimation.html">NumberAnimation</a></span> { <span style="color:black;">target</span>: <span style="color:black;">wrapper</span>; <span style="color:black;">property</span>: <span>"scale"</span>; <span style="color:black;">to</span>: <span>0</span>; <span style="color:black;">duration</span>: <span>250</span>; <span style="color:black;">easing</span>.type: <span style="color:black;">Easing</span>.<span style="color:black;">InOutQuad</span> }             <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(0,115,47); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-propertyaction.html">PropertyAction</a></span> { <span style="color:black;">target</span>: <span style="color:black;">wrapper</span>; <span style="color:black;">property</span>: <span>"ListView.delayRemove"</span>; <span style="color:black;">value</span>: <span>false</span> }         }     } }

read-onlyListView.isCurrentItem : bool

This attached property is true if this delegate is the current item; otherwise false.

如果这个delegate是当前项则这个附加属性为true,否则为false。

It is attached to each instance of the delegate.

它被赋予每个delegate的实例。

This property may be used to adjust the appearance of the current item, for example:

这个属性可被用于判断当前项的显示。

 <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-listview.html">ListView</a></span> {     <span style="color:black;">width</span>: <span>180</span>; <span style="color:black;">height</span>: <span>200</span>     <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-component.html">Component</a></span> {         <span style="color:black;">id</span>: <span style="color:black;">contactsDelegate</span>         <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(15,83,0); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-rectangle.html">Rectangle</a></span> {             <span style="color:black;">id</span>: <span style="color:black;">wrapper</span>             <span style="color:black;">width</span>: <span>180</span>             <span style="color:black;">height</span>: <span style="color:black;">contactInfo</span>.<span style="color:black;">height</span>             <span style="color:black;">color</span>: <span style="color:black;">ListView</span>.<span style="color:black;">isCurrentItem</span> ? <span>"black"</span> : <span>"red"</span>             <span style="FONT-WEIGHT: bold" class="type"><a target=_blank style="COLOR: rgb(0,115,47); TEXT-DECORATION: none" href="http://write.blog.csdn.net/qml-text.html">Text</a></span> {                 <span style="color:black;">id</span>: <span style="color:black;">contactInfo</span>                 <span style="color:black;">text</span>: <span style="color:black;">name</span> <span style="color:#202020;">+</span> <span>": "</span> <span style="color:#202020;">+</span> <span style="color:black;">number</span>                 <span style="color:black;">color</span>: <span style="color:black;">wrapper</span>.<span style="color:black;">ListView</span>.<span style="color:black;">isCurrentItem</span> ? <span>"red"</span> : <span>"black"</span>             }         }     }     <span style="color:black;">model</span>: <span style="color:black;">ContactModel</span> {}     <span style="color:black;">delegate</span>: <span style="color:black;">contactsDelegate</span>     <span style="color:black;">focus</span>: <span>true</span> }

read-onlyListView.nextSection : string

This attached property holds the section of the next element.

这个附加属性持有下个元素的分段。

It is attached to each instance of the delegate.

它被赋予每个delegate的实例。

The section is evaluated using the section properties.

这个分段由section属性来评估。


read-onlyListView.previousSection : string

This attached property holds the section of the previous element.

这个附加属性持有上个元素的分段。

 

It is attached to each instance of the delegate.

它被赋予每个delegate的实例。

 

The section is evaluated using the section properties.

这个分段由section属性来评估。


 


read-onlyListView.section : string

This attached property holds the section of this element.

这个附加属性持有这个元素的分段。

 

It is attached to each instance of the delegate.

它被赋予每个delegate的实例。

 

The section is evaluated using the section properties.

这个分段由section属性来评估。

 


read-onlyListView.view : ListView

This attached property holds the view that manages this delegate instance.

这个附加属性持有用来管理这个delegate的实例的视图。

It is attached to each instance of the delegate.

它被赋予delegate的实例。


Attached Signal Documentation

ListView::onAdd ()

This attached handler is called immediately after an item is added to the view.


ListView::onRemove ()

This attached handler is called immediately before an item is removed from the view.


Method Documentation

ListView::decrementCurrentIndex ()

Decrements the current index. The current index will wrap if keyNavigationWraps is true and it is currently at the beginning. This method has no effect if the countis zero.

Note: methods should only be called after the Component has completed.


ListView::incrementCurrentIndex ()

Increments the current index. The current index will wrap if keyNavigationWraps is true and it is currently at the end. This method has no effect if the count is zero.

Note: methods should only be called after the Component has completed.


int ListView::indexAt ( int x, int y )

Returns the index of the visible item containing the point x, y in content coordinates. If there is no item at the point specified, or the item is not visible -1 is returned.

If the item is outside the visible area, -1 is returned, regardless of whether an item will exist at that point when scrolled into view.

Note: methods should only be called after the Component has completed.


ListView::positionViewAtIndex ( int index, PositionMode mode )

Positions the view such that the index is at the position specified by mode:

  • ListView.Beginning - position item at the top (or left for horizontal orientation) of the view.
  • ListView.Center - position item in the center of the view.
  • ListView.End - position item at bottom (or right for horizontal orientation) of the view.
  • ListView.Visible - if any part of the item is visible then take no action, otherwise bring the item into view.
  • ListView.Contain - ensure the entire item is visible. If the item is larger than the view the item is positioned at the top (or left for horizontal orientation) of the view.

If positioning the view at index would cause empty space to be displayed at the beginning or end of the view, the view will be positioned at the boundary.

It is not recommended to use contentX or contentY to position the view at a particular index. This is unreliable since removing items from the start of the list does not cause all other items to be repositioned, and because the actual start of the view can vary based on the size of the delegates. The correct way to bring an item into view is with positionViewAtIndex.

Note: methods should only be called after the Component has completed. To position the view at startup, this method should be called by Component.onCompleted. For example, to position the view at the end:

[cpp] view plaincopyprint?
  1. Component<SPAN style="COLOR: #202020">.</SPAN>onCompleted: positionViewAtIndex(count <SPAN style="COLOR: #202020">-</SPAN> <SPAN>1</SPAN><SPAN style="COLOR: #202020">,</SPAN> ListView<SPAN style="COLOR: #202020">.</SPAN>Beginning)  

0 0
原创粉丝点击