简体   繁体   中英

Can't select row of TableView in QML

I have created a TableView in QML, connected to a SoftFilterProxyModel. The data displays fine, and when I click on a row my "selectRow" function runs, and receives the correct row number. However, nothing shows as selected. I based my design on this 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)?

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() . For more selection flags you can read this . Replace s and c of select and current with capital letter.

companyTableISM.select(companySFPM.index(row, 0), ItemSelectionModel.Select | ItemSelectionModel.Current);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM