0
我使用TableView填充文本。其中一列具有复选框作为代表。我检查其中一个复选框。我怎样才能获得当前复选框的行索引?在qml中获取选中复选框的行索引
获取行索引我使用currentRow函数,但它返回-1,因为当我检查复选框时,我不选择行。
是否有任何其他方式来获取复选框行索引?
我使用TableView填充文本。其中一列具有复选框作为代表。我检查其中一个复选框。我怎样才能获得当前复选框的行索引?在qml中获取选中复选框的行索引
获取行索引我使用currentRow函数,但它返回-1,因为当我检查复选框时,我不选择行。
是否有任何其他方式来获取复选框行索引?
有太多的可能性来做到这一点。其中一人的一些很简单的例子:
import QtQuick 2.7
import QtQuick.Window 2.0
import QtQuick.Controls 1.4
Window {
visible: true
width: 300
height: 200
TableView {
id: table
anchors.fill: parent
signal checked(int row, int col, bool isChecked)
TableViewColumn { role: "col1"; title: "Columnt1"; width: 100 }
TableViewColumn { role: "col2"; title: "Columnt2"; width: 100 }
TableViewColumn { role: "col3"; title: "Columnt3"; width: 100 }
model: ListModel {
ListElement { col1: true; col2: false; col3: false }
ListElement { col1: false; col2: false; col3: true }
ListElement { col1: true; col2: false; col3: true }
}
itemDelegate: Item {
CheckBox {
anchors.centerIn: parent
checked: styleData.value
onClicked: {
table.selection.clear();
table.selection.select(styleData.row);
table.currentRow = styleData.row;
table.checked(styleData.row, styleData.column, checked);
}
}
}
onChecked: console.log(row, col, isChecked);
}
}
邮政QML代码,特别是代表 –
检查此线程Qt的论坛,你想要做什么是类似于:http://www.qtforum.org /article/36990/returning-row-s-number-after-clicking-qpushbutton.html –
像所有其他通过'styleData与单元格相关的值?正如@folibis的答案所示。不知道如何在没有'styleData'的情况下让显示工作 –