Package Element Reference

Package provides a collection of named items.

Detailed Description

Package provides a collection of named items.

The Package class is used in conjunction with VisualDataModel to enable delegates with a shared context to be provided to multiple views.

Any item within a Package may be assigned a name via the Package.name attached property.

The example below creates a Package containing two named items; list and grid. The third element in the package (the Rectangle) is parented to whichever delegate it should appear in. This allows an item to move between views.

  1. Package  {
  2.     Text  { id: listDelegate; width: 200; height: 25; text: 'Empty'; Package.name: 'list' }
  3.     Text  { id: gridDelegate; width: 100; height: 50; text: 'Empty'; Package.name: 'grid' }
  4.  
  5.     Rectangle  {
  6.         id: wrapper
  7.         width: 200; height: 25
  8.         color: 'lightsteelblue'
  9.  
  10.         Text  { text: display; anchors.centerIn: parent }
  11.         MouseArea  {
  12.             anchors.fill: parent
  13.             onClicked:  {
  14.                 if (wrapper.state == 'inList')
  15.                     wrapper.state = 'inGrid';
  16.                 else
  17.                     wrapper.state = 'inList';
  18.             }
  19.         }
  20.  
  21.         state: 'inList'
  22.         states: [
  23.             State  {
  24.                 name: 'inList'
  25.                 ParentChange  { target: wrapper; parent: listDelegate }
  26.             },
  27.             State  {
  28.                 name: 'inGrid'
  29.                 ParentChange  {
  30.                     target: wrapper; parent: gridDelegate
  31.                     x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height
  32.                 }
  33.             }
  34.         ]
  35.  
  36.         transitions: [
  37.             Transition  {
  38.                 ParentAnimation  {
  39.                     NumberAnimation  { properties: 'x,y,width,height'; duration: 300 }
  40.                 }
  41.             }
  42.         ]
  43.     }
  44. }

These named items are used as the delegates by the two views who reference the special VisualDataModel::parts property to select a model which provides the chosen delegate.

  1.                 VisualDataModel  {
  2.     id: visualModel
  3.     delegate: Delegate  {}
  4.     model: myModel
  5. }
  6.  
  7. ListView  {
  8.     width: 200; height:200
  9.     model: visualModel.parts.list
  10. }
  11. GridView  {
  12.     x: 200; width: 200; height:200
  13.     cellHeight: 50
  14.     model: visualModel.parts.grid
  15. }

Attached Properties

Attached Property Documentation

This attached property holds the name of an item within a Package.

Notes provided by the Qt Community

No notes