Presenting Data with Views
Views are containers for collections of items. They are feature-rich and can be customizable to meet style or behavior requirements.
A set of standard views are provided in the basic set of Qt Quick graphical elements:
- ListView arranges items in a horizontal or vertical list
- GridView arranges items in a grid within the available space
- PathView arranges items on a path
- WebView - available from the QtWebKit QML Module.
Unlike other views, WebView is not a fully-featured view item, and needs to be combined with a Flickable item to create a view that performs like a Web browser.
These elements have properties and behaviors exclusive to each element. Visit their respective documentation for more information.
Models
Views display models onto the screen. A model could be a simple list of integer or a C++ model.
To assign a model to a view, bind the view's model
property to a model.
For more information, consult the QML Data Models article.
View Delegates
Views need a delegate to visually represent an item in a list. A view will visualize each item list according to the template defined by the delegate. Items in a model are accessible through the index
property as well as the item's properties.
[Missing image listview-setup.png]
Decorating Views
Views allow visual customization through decoration properties such as the header
, footer
, and section
properties. By binding an object, usually another visual object, to these properties, the views are decoratable. A footer may include a Rectangle element showcasing borders or a header that displays a logo on top of the list.
Suppose that a specific club wants to decorate its members list with its brand colors. A member list is in a model
and the delegate
will display the model's content.
The club may decorate the members list by binding visual objects to the header
and footer
properties. The visual object may be defined inline, in another file, or in a Component element.
[Missing image listview-decorations.png]
ListView Sections
ListView contents may be grouped into sections, where related list items are labeled according to their sections. Further, the sections may be decorated with delegates.
A list may contain a list indicating people's names and the team on which team the person belongs.
The ListView element has the section
attached property that can combine adjacent and related elements into a section. The section's property
property is for selecting which list element property to use as sections. The criteria
can dictate how the section names are displayed and the delegate
is similar to the views' delegate property.
[Missing image listview-section.png]