【发布时间】:2017-07-03 15:26:39
【问题描述】:
我启用了材料设计(深色主题)。
一些教程告诉我使用背景属性来设置我自己的带有自定义颜色的矩形项目。就像在这个屏幕截图中一样:
但是使用这种技术,我不再有这些漂亮的涟漪效应了。我想做的只是改变所有项目的背景和文本颜色。
所以我尝试更改背景属性但没有运气。启动时调试输出告诉我背景中没有颜色属性。
所以我想出了一个使用绑定的“hacky”方式......现在属性存在!?
这是实现我的目标的最佳方式吗?点击时会出现涟漪效应,但我对此感觉不好。我不明白为什么在使用绑定时该属性存在,以及为什么在使用普通数据绑定时它们不存在。
ItemDelegate {
width: ListView.view.width
height: contentItem.implicitHeight + 10
topPadding: 5
bottomPadding: 5
highlighted: ListView.view.currentIndex === model.index
//background.color: highlighted ? "#81A3CF" : "#B3B2B2"
Binding {
target: background
property: "color"
value: highlighted ? "#81A3CF" : "#B3B2B2"
}
text: model.index + (highlighted ? " [highlighted]" : "")
//contentItem.color: "black"
Binding {
target: contentItem
property: "color"
value: "black"
}
onClicked: {
if(ListView.view.currentIndex === model.index)
ListView.view.currentIndex = -1;
else
ListView.view.currentIndex = model.index
}
}
【问题讨论】:
标签: qt qml qtquick2 qtquickcontrols2