【发布时间】:2015-09-23 01:48:24
【问题描述】:
我想将 QtGraphicalEffect ColorOverlay 应用于 Repeater 委托中的 Image。问题是我必须将Image的id设置为ColorOverlay的source,但我不知道id,因为它是由Repeater动态创建的。
import QtQuick 2.4
import QtGraphicalEffects 1.0
Item {
id:mainItem
width: 800
height: 400
property string vorneColor: "red"
ListModel {
id: safeRailModel
ListElement {name: "vorne"; imageSource:"images/saferail/ring_vorne.png";}
ListElement {name: "vorneLinks"; imageSource:"images/saferail/ring_vorne_links.png"; }
}
Component {
id: imageDelegate
Image {
source: imageSource
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
fillMode: Image.PreserveAspectFit
opacity: 1
visible: true
}
}
Repeater {
id: safeRailRepeater
model: safeRailModel
delegate: imageDelegate
}
Component {
id: effectsDelegate
Item{
id:effectsItem
ColorOverlay {
anchors.fill: safeRailRepeater.itemAt(index)// <-- This doesn't work
source: safeRailRepeater.itemAt(index)// <-- This doesn't work
color: vorneColor
}
}
}
Repeater {
id: safeRailEffectsRepeater
model: safeRailModel
delegate: effectsDelegate
}
}
如何设置source 和anchors.fill 属性?
我到处搜索,但我只找到了类似于safeRailRepeater.itemAt(index) 或safeRailRepeater.itemAt(index).item 的东西,但前者和后者都不起作用。
旁注:ColorOverlay 不需要位于单独的委托和 Repeater 中。
如果有人能解决这个问题或者可以为我指明正确的方向,那就太好了。
非常感谢!
【问题讨论】: