PDA

View Full Version : QListView: How to move the cursor to a specific row



muellerp
20th November 2008, 17:26
Hello,

I have a QListView with >100 entries.

I have the issue, that I can move the selection with code, but not the cursor.

Let's make an example:

1) I click on the first entry in the list.
2) The entry get's selected
3) At a later time, I use QItemSelectionModel->select( ...row 50 ... , QItemSelectionModel::ClearAndSelect )
4) I also use QListView->scrollTo ( ... row 50 ..., QAbstractItemView::PositionAtCenter )

Now the row 50 is selected and is in the middle of the QListView.

So far so good and as expected.

But if I then press the cursor key down, the QListView jumps to row 2 instead of row 51.

So the selection I can define, but not where the cursor is.

In QListView I can find method for moving to first, last, next, ... but not something moveTo (row = 50).

Do you have any hint for me, where to look for getting the cursor also moved to row 50?
Anyway, I don't need a cursor different to the selection in any case.

caduel
20th November 2008, 21:47
have you tried calling QAbstractItemView::setCurrentIndex()?

muellerp
21st November 2008, 07:29
Thanks,

that's exactly what I was searching for.