Presenting Data with ViewsViews 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:
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. ModelsViews 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. ListModel { id: petlist ListElement { type: "Cat" } ListElement { type: "Dog" } ListElement { type: "Mouse" } ListElement { type: "Rabbit" } ListElement { type: "Horse" } } ListView { id: view anchors.fill: parent model: petlist delegate: petdelegate } For more information, consult the QML Data Models article. View DelegatesViews 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. Component { id: petdelegate Text { id: label font.pixelSize: 24 text: if (index == 0) label.text = type + " (default)" else text: type } } 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. 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. |