Can't select row of TableView in QML

735 views Asked by At

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)?

2

There are 2 answers

0
TSG On BEST ANSWER

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
0
smalik On

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);