VisualItemModel Element Reference

The VisualItemModel allows items to be provided to a view.

This element was introduced in Qt 4.7.

Detailed Description

The VisualItemModel allows items to be provided to a view.

A VisualItemModel contains the visual items to be used in a view. When a VisualItemModel is used in a view, the view does not require a delegate since the VisualItemModel already contains the visual delegate (items).

An item can determine its index within the model via the index attached property.

The example below places three colored rectangles in a ListView.

  1. import QtQuick 1.0
  2.  
  3. Rectangle  {
  4.     VisualItemModel  {
  5.         id: itemModel
  6.         Rectangle  { height: 30; width: 80; color: "red" }
  7.         Rectangle  { height: 30; width: 80; color: "green" }
  8.         Rectangle  { height: 30; width: 80; color: "blue" }
  9.     }
  10.  
  11.     ListView  {
  12.         anchors.fill: parent
  13.         model: itemModel
  14.     }
  15. }

Properties

Attached Properties

Property Documentation

The number of items in the model. This property is readonly.

Attached Property Documentation

  • VisualItemModel.index : int

This attached property holds the index of this delegate's item within the model.

It is attached to each instance of the delegate.

Notes provided by the Qt Community

No notes