TableView - 如何在不丢失 styleData.selected 的情况下获得悬停的行 [英] TableView - How to get hovered row without loosing styleData.selected
问题描述
我需要突出显示 TableView
中悬停的行.默认情况下没有悬停效果.我可以在 rowDelegate
中使用 MouseArea
来实现这一点.但这将禁用 TableView
中的选择机制.
I need to highlight the hovered row in a TableView
.
By default there is no hovering effect.
I can use a MouseArea
inside rowDelegate
to achieve this.
But this will disable selection mechanism in TableView
.
意味着 styleData.selected
将不再起作用.这意味着我必须为包括扩展选择在内的选择机制编写每一行代码.
Means styleData.selected
will not work anymore.
Which means I have to program each and every line of code for the selection mechanism including extended selection.
如何解决这个问题?我只需要像 ScrollViewStyle
How to solve this issue? I just need a little property such as styleData.hovered
like in handle
component of ScrollViewStyle
这个问题已经问了 3 年 &2个月前.很遗憾没有得到答复.
The question is already asked 3 years & 2 months ago. Unanswered unfortunately.
QML 如何将鼠标悬停与 styleData 一起使用.selected
更新
rowDelegate: Rectangle {
height: 30
property color selectedColor: styleData.hasActiveFocus ? "gray" : "lightgray"
color: styleData.selected ? selectedColor : mouse_area.hovered?"black":backgroundColor
MouseArea{
id:mouse_area
property bool hovered:false
propagateComposedEvents : false
hoverEnabled: true
anchors.fill: parent
onEntered: {
hovered=true
}
onExited: {
hovered=false;
}
}
}
推荐答案
添加:
MouseArea {
// ...
onPressed: mouse.accepted = false
}
会将鼠标信号传播到 TableView
并保持其选择行为.
will propagate the mouse signal to the TableView
and keep its selection behavior.
这篇关于TableView - 如何在不丢失 styleData.selected 的情况下获得悬停的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!