ListItemComponent

Specifies a QML template used by a ListView to display items.

A ListItemComponent can be attached to a list view using the ListView::listItemComponents property, and it can contain whatever QML components that you want to display in your list item.

The type property is used to specify the type of item that the ListItemComponent is used for (for example, you might have one ListItemComponent used for "contacts" and another for "groups", each of which has a unique visual appearance).

Here's how to create two ListItemComponent objects and add them to a list. One of the list item components is for a "header" and the other is for a standard "item".

ListView {
    dataModel: XmlDataModel { source: "model.xml" }
    listItemComponents: [
        ListItemComponent {
            type: "header"
            
            Label {
                text: ListItemData.title
            }
        },

        ListItemComponent {
            type: "item"

            Container {
                layout: StackLayout {
                    orientation: LayoutOrientation.LeftToRight
                }
                ImageView {
                    imageSource: ListItemData.image
                }
                Label {
                    text: ListItemData.title
                }
            }
        }
    ]
}
Note:

This class can only be used in QML. In C++, the visuals for list items can be managed using ListItemProvider.


Overview

QML properties

content: QDeclarativeComponent
type: QString

Properties Index

QDeclarativeComponentcontent
QStringtype

Public Functions Index

ListItemComponent (QObject *parent=0)
QDeclarativeComponent *content () const
voidsetContent (QDeclarativeComponent *component)
voidsetType (const QString &typeString)
QStringtype () const

Signals Index

voidcontentChanged (QDeclarativeComponent *content)
voidtypeChanged (QString type)

Properties

QDeclarativeComponent content

Item visuals are defined on this property.

This is the default property for ListItemComponent.

Since this property is of the type QDeclarativeComponent*, it does not contain instances of Control objects. Neither can object instances be assigned to this property. Instead, the QML from this property is used by a ListView to create item visuals of the specified type when needed. Which means that symbols only available in item visuals (for example ListItemData) can be used in the QML on this property, since the symbols are not resolved until a ListView creates item visuals. On the other hand, symbols only available in the context of this ListItemComponent cannot be used in the QML on this property, because item visuals are created in contexts of their own. Data can however be communicated to the item visuals by setting it as a dynamic property on this ListItemComponent, or on the ListView. The values from such dynamic properties are available from the symbols ListItem.component and ListItem.view in the item visuals.

QString type

The type of items this ListItemComponent should be used for.

The default value is an empty string.

Public Functions

ListItemComponent (

Construct a ListItemComponent instance.

QDeclarativeComponent * content ()

Item visuals are defined on this property.

This is the default property for ListItemComponent.

Since this property is of the type QDeclarativeComponent*, it does not contain instances of Control objects. Neither can object instances be assigned to this property. Instead, the QML from this property is used by a ListView to create item visuals of the specified type when needed. Which means that symbols only available in item visuals (for example ListItemData) can be used in the QML on this property, since the symbols are not resolved until a ListView creates item visuals. On the other hand, symbols only available in the context of this ListItemComponent cannot be used in the QML on this property, because item visuals are created in contexts of their own. Data can however be communicated to the item visuals by setting it as a dynamic property on this ListItemComponent, or on the ListView. The values from such dynamic properties are available from the symbols ListItem.component and ListItem.view in the item visuals.

void setContent (
  • QDeclarativeComponent *component)

Item visuals are defined on this property.

This is the default property for ListItemComponent.

Since this property is of the type QDeclarativeComponent*, it does not contain instances of Control objects. Neither can object instances be assigned to this property. Instead, the QML from this property is used by a ListView to create item visuals of the specified type when needed. Which means that symbols only available in item visuals (for example ListItemData) can be used in the QML on this property, since the symbols are not resolved until a ListView creates item visuals. On the other hand, symbols only available in the context of this ListItemComponent cannot be used in the QML on this property, because item visuals are created in contexts of their own. Data can however be communicated to the item visuals by setting it as a dynamic property on this ListItemComponent, or on the ListView. The values from such dynamic properties are available from the symbols ListItem.component and ListItem.view in the item visuals.

void setType (

The type of items this ListItemComponent should be used for.

The default value is an empty string.

QString type ()

The type of items this ListItemComponent should be used for.

The default value is an empty string.

Signals

void contentChanged (
  • QDeclarativeComponent *content)

Emitted when ListItemComponent::content has changed.

void typeChanged (

Emitted when ListItemComponent::type has changed.

Last modified: 2014-03-13

comments powered by Disqus