首页| 论坛| 消息
主题:如何在TableView里面实现全选功能?
expressw发表于 2018-01-22 16:04
我实现了一个TableView,
其中第一列是一个CheckBox
TableViewColumn {
role :""
title: ""
width: 90
delegate: Rectangle {
CheckBox {
anchors.centerIn: parent;
Connections {
target: alarmTable.headerRect.checkForAll;
onAllCheckChanged: {
console.log("---haha");
}
}
}
}
然后在TableView的headerDelegate里面实现表格头部第一列也是一个CheckBox:
headerDelegate: Rectangle {
id: headerRect;
height: 60
color: "#B7B7B7"
CheckBox {
id: checkForAll;
anchors.centerIn: parent;
visible: styleData.column === 0;
property bool myPressed: styleData.pressed;
onMyPressedChanged: {
if (myPressed) {
checked = !checked;
}
}
}
Text {
id: textItem
anchors.centerIn: parent
verticalAlignment: Text.AlignVCenter
horizontalAlignment: styleData.textAlignment
anchors.leftMargin: 12
text: styleData.value
font.pixelSize: 20
elide: Text.ElideMiddle
color: "#333333"
renderType: Text.NativeRendering
}
}
我想在点击表头中checkForAll的时候,把表格中每一行的CheckBox都勾上,但是现在遇到困难:
1. 直接的办法就是找到每一个CheckBox把checked置为true,但是没有找到办法,可以遍历TableView中的每一行,然后取到其中的CheckBox控件;
2. 想用signal/slot的方法,但是在TableViewColumn中的CheckBox中绑定checkForAll的信号的时候,总是提示:
QML Connections: Cannot assign to non-existent property "onAllCheckChanged"
ReferenceError: checkForAll is not defined
请问这有什么好的处理办法吗?多谢。
回帖(2):
2楼:你好,我header的信号点击出发四次怎么回事啊?

headerDelegate: Item {
height: ..
1楼:找到办法了:
数据model是在C++中定义的,model里面增加一个属性checked;
列的role设置 ..

全部回帖(2)»
最新回帖
收藏本帖
发新帖