I guess my question fits this thread, but solution given in last post I think isn't apropriate for Qt4.
So, what exactly I want to do. I have a widget with QListView, QDirModel and QSelectionModel and actually I want the widget to remember activated directory, so when I come back cursor/highlighting will be on that directory.
Example:
we have following items in current dir:
. .. pics walls sample.png pict.jpg
What is default: Key_Down x 3 /*go to pics*/, Key_Return, ... , <go to "..">, enter, Key_Down x 4 /*go to walls*/, enter.
What I want: Key_Down x 3 /*go to pics*/, enter, ..., <go to "..">, enter, Key_Down x 1 /*go to walls*/, enter.
setCurrentIndex() doesn't work, it sets but doesn't highlight that. And you can then press Key_{Return,Enter} (btw are they equal? I know that they have different values, but anyway...) and activate it, but if you press Key_Down you will be at "."
How to solve the problem? I don't need the full code for this =) but just wanna know how to set position of List View cursor.
offtopic
How to get rid of "." item, but keep ".."? I know about QDir::NoDotAndDotDot, but what about QDir::NoDot ?
updated
Ok, found this in QListWidget::setItemSelected(const QListWidgetItem *item, bool select)
if (d->selectionMode == SingleSelection) {
selectionModel()->select(index, select
}
if (d->selectionMode == SingleSelection) {
selectionModel()->select(index, select
? QItemSelectionModel::ClearAndSelect
: QItemSelectionModel::Deselect);
}
To copy to clipboard, switch view to plain text mode
But when I come into /home/eruart/imgs code:
selmodel
->select
(dirmodel
->index
("/home/eruart/imgs/example.png"),
QItemSelectionModel::ClearAndSelect);
selmodel->select(dirmodel->index("/home/eruart/imgs/example.png"), QItemSelectionModel::ClearAndSelect);
To copy to clipboard, switch view to plain text mode
gives me following in console:
intersectingStaticSet: row 11 was invalid
intersectingStaticSet: row 12 was invalid
What does it mean?
update 2
if (!dirmodel->fileName(current).contains("..")) last = current;
qDebug() << last;
static QModelIndex last;
if (!dirmodel->fileName(current).contains("..")) last = current;
qDebug() << last;
listview->selectionModel()->select(last,QItemSelectionModel::ClearAndSelect);
To copy to clipboard, switch view to plain text mode
current here is const QModelIndex & that passed by listview's activated signal, and this code is handleActivated slot that connected with the signal.
intersectingStaticSet: row 11 was invalid
intersectingStaticSet: row 12 was invalid
~/imgs $ ls -a | wc
11 12 135
QModelIndex(4,0,0x80984a8,QDirModel(0x8082aa8) )
intersectingStaticSet: row 11 was invalid
intersectingStaticSet: row 12 was invalid
~/imgs $ ls -a | wc
11 12 135
To copy to clipboard, switch view to plain text mode
Why rows 11 and 12, but not 4?
Bookmarks