Julien Lopez
Julien Lopez

Reputation: 1021

QTableView, select and shift+click

I have a small but quite annoying problem with Qt's QTableView

Since my view is used in a StackedLayout, I have to select a line based on a field in an other page (that part works ok).

So when I display this view, I select the line I want with a simple

QItemSelection selection = line2selection(line);
d_view->selectionModel()->select(selection, QItemSelectionModel::Select);

where line2selection creates a QItemSelection filled with all the indexes for the whole line.

As I sais, this part works ok, but introduce another problem:

When I do a shift+click to select several lines at once (which works great if I don't select a line "programatically"), it always stars the selection from the first line instead of the starting from the line currently selected.

Any idea how I could fix the problem?

btw, I tried to call the selectRow method on my view too, but doesn't seem to be much better...

Upvotes: 0

Views: 776

Answers (1)

ratchet freak
ratchet freak

Reputation: 48186

add the QItemSelectionModel::Current flag to QItemSelectionModel::Select so the "current" item index is updated, this index acts as the anchor for the shift+click multi-selects

Upvotes: 1

Related Questions