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'的情況下讓顯示工作 –