单击 TableViewColumn 时如何发出信号?
How do I emit signal while clicking TableViewColumn?
我想将 MouseArea
/Button
添加到 TableViewColumn
以执行特定任务。但是,如果我添加上述类型之一,它会覆盖 TableViewColumn
的 "click" 事件,这样我就失去了行选择。
这是一个示例代码。当我在最后一列的区域中单击它时,该行没有切换:
TreeView {
clip: true id: mapsTreeView
objectName: "mapsTreeView"
model: theModel
TableViewColumn {
width: 100
role: "name_role"
title: "Map"
}
TableViewColumn {
width: 50
role: "description_role"
}
TableViewColumn {
id: imageColumn
width: 20
role: "image_role"
delegate: Item {
MouseArea {
anchors.fill: parent
onClicked: {
mapsTreeView.sigChangeState()
}
}
Image {
anchors.fill: parent
width: 5
source: "icon" + styleData.value + ".png"
}
}
}
signal sigChangeState()
}
也许有更好的解决方案,但这对我有用:
MouseArea {
anchors.fill: parent
onContainsPressChanged: {
if(containsPress)
{
console.log("PRESSED")
}
}
onPressed: {
mouse.accepted = false
}
}
我想将 MouseArea
/Button
添加到 TableViewColumn
以执行特定任务。但是,如果我添加上述类型之一,它会覆盖 TableViewColumn
的 "click" 事件,这样我就失去了行选择。
这是一个示例代码。当我在最后一列的区域中单击它时,该行没有切换:
TreeView {
clip: true id: mapsTreeView
objectName: "mapsTreeView"
model: theModel
TableViewColumn {
width: 100
role: "name_role"
title: "Map"
}
TableViewColumn {
width: 50
role: "description_role"
}
TableViewColumn {
id: imageColumn
width: 20
role: "image_role"
delegate: Item {
MouseArea {
anchors.fill: parent
onClicked: {
mapsTreeView.sigChangeState()
}
}
Image {
anchors.fill: parent
width: 5
source: "icon" + styleData.value + ".png"
}
}
}
signal sigChangeState()
}
也许有更好的解决方案,但这对我有用:
MouseArea {
anchors.fill: parent
onContainsPressChanged: {
if(containsPress)
{
console.log("PRESSED")
}
}
onPressed: {
mouse.accepted = false
}
}