标题:如何在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");
}
..
#1 [expressw 01-22 17:43]
找到办法了:
数据model是在C++中定义的,model里面增加一个属性checked;
列的role设置为模式中的checked;
列的checkbox响应点击事件,同步修改model中的checked标记:
TableViewColumn {
role :"checked"
title: ""
width: 90
delegate: Rectangle {
CheckBox {
id: rowCheck;
anchors.centerIn: parent;
checked: styleData.value;
onPressed: {
alarmModel.setRowCheckState(styleData.row, !checked);
}
}
  ..
#2 [kettong 02-21 20:02]
你好,我header的信号点击出发四次怎么回事啊?
headerDelegate: Item {
height: 20
anchors.left: parent.left
anchors.right: parent.right
CheckBox {
id: activateAllEvents
anchors.centerIn: parent
property bool myPressed: styleData.pressed
checked: true
visible: styleData.column === 4 // Show only in the 4th column
activeFocusOnPress: true
text: ""
onMyPressedChaged: {
if(myPressed)
&n ..