[英]Can't select row of TableView in QML
I have created a TableView in QML, connected to a SoftFilterProxyModel.我在 QML 中创建了一个 TableView,连接到 SoftFilterProxyModel。 The data displays fine, and when I click on a row my "selectRow" function runs, and receives the correct row number.数据显示正常,当我单击一行时,我的“selectRow”function 运行,并收到正确的行号。 However, nothing shows as selected.但是,没有任何内容显示为选中状态。 I based my design on this SO question我的设计基于这个 SO question
The relevant code is:相关代码为:
ItemSelectionModel {
id: companyTableISM
model: companySFPM
}
function selectRow(row) {
console.log("In selectRow row "+row);
companyTableISM.select(companySFPM.index(row, 0), ItemSelectionModel.select | ItemSelectionModel.current );
console.log(companyTableISM.selectedIndexes);
console.log(companyTableISM.hasSelection);
}
So when I click a row it outputs:因此,当我单击一行时,它会输出:
qml: In selectRow row 3
qml: []
qml: false
Since my selectRow function is receiving the correct row number, the model (companySFPM) matches the one used by the TableView, why do my 2 log statements showing nothing selected and false (hasSelection)?由于我的 selectRow function 接收到正确的行号,model (companySFPM)与 TableView 使用的匹配,为什么我的 2 个日志语句显示没有选择和错误(hasSelection)?
I believe you have two typos in the line:我相信你有两个错别字:
ItemSelectionModel.select | ItemSelectionModel.current
Notice the capitalization of the enumerated types?注意枚举类型的大小写? It should be:它应该是:
ItemSelectionModel.Select | ItemSelectionModel.Current
Current and Select are selection flags enum of select()
. Current 和 Select 是select()
的选择标志枚举。 For more selection flags you can read this .有关更多选择标志,您可以阅读此内容。 Replace s and c of select and current with capital letter.将 select 和 current 的 s 和 c 替换为大写字母。
companyTableISM.select(companySFPM.index(row, 0), ItemSelectionModel.Select | ItemSelectionModel.Current);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.