Qt QML如何将鼠标悬停与styleData.selected一起使用
我正在尝试为TableView中的行构建一个简单的委托。 我希望它在鼠标悬停时显示边框,在选中时留下边框。见下面的代码:Qt QML如何将鼠标悬停与styleData.selected一起使用,qt,qml,Qt,Qml,我正在尝试为TableView中的行构建一个简单的委托。 我希望它在鼠标悬停时显示边框,在选中时留下边框。见下面的代码: Component { id: rowDelegate Item { height: 40 Rectangle { id: rowRectSel anchors.fill: parent color: "grey" radius: 2
Component
{
id: rowDelegate
Item
{
height: 40
Rectangle
{
id: rowRectSel
anchors.fill: parent
color: "grey"
radius: 2
opacity: 0.4
border.width: 3;
visible: styleData.selected
}
Rectangle
{
id: rowRect
anchors.fill: parent
color: "grey"
radius: 2
opacity: 0.4
border.width: 1;
visible: !styleData.selected
}
MouseArea
{
id: rowMouseA
hoverEnabled: true
anchors.fill: parent
preventStealing: false
propagateComposedEvents: true
enabled: !styleData.selected
}
states:
[
State
{
name: "hover"
when: rowMouseA.containsMouse
PropertyChanges { target: rowRect; border.width: 2; }
}
]
}
问题是当MouseArea(rowMouseA)存在时,它不会显示rowRectSel-以某种方式阻止行更改styleData.selected属性。
如果我删除MouseArea或将enabled属性设置为false,则选中时rowRectSel将可见。ist styleData定义在何处?在此情况下,它被称为“特殊属性”。可能重复