qml package 的使用

什么时候使用这个。就是多个view使用同一个deleagte的时候。

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 item in the package (the Rectangle) is parented to whichever delegate it should appear in. This allows an item to move between views.

Package {
Text { id: listDelegate; width: parent.width; height: 25; text: 'Empty'; Package.name: 'list' }
Text { id: gridDelegate; width: parent.width / 2; height: 50; text: 'Empty'; Package.name: 'grid' }

Rectangle {
    id: wrapper
    width: parent.width; height: 25
    color: 'lightsteelblue'

    Text { text: display; anchors.centerIn: parent }
    state: root.upTo > index ? 'inGrid' : 'inList'
    states: [
        State {
            name: 'inList'
            ParentChange { target: wrapper; parent: listDelegate }
        },
        State {
            name: 'inGrid'
            ParentChange {
                target: wrapper; parent: gridDelegate
                x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height
            }
        }
    ]

    transitions: [
        Transition {
            ParentAnimation {
                NumberAnimation { properties: 'x,y,width,height'; duration: 300 }
            }
        }
    ]
}

}
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.

DelegateModel {
id: visualModel
delegate: Delegate {}
model: myModel
}

ListView {
id: lv
height: parent.height/2
width: parent.width

model: visualModel.parts.list

}
GridView {
y: parent.height/2
height: parent.height/2
width: parent.width
cellWidth: width / 2
cellHeight: 50
model: visualModel.parts.grid
}

转载于:https://www.cnblogs.com/xianqingzh/p/4497899.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值