I am using QFileSystemModel
along with QListView
, and I want the first item shown by the model to get selected by default.
How I do that every time I click an item ?
I am using QFileSystemModel
along with QListView
, and I want the first item shown by the model to get selected by default.
How I do that every time I click an item ?
Using setCurrentIndex
should do the job:
view->setCurrentIndex(fsModel->index(0, 0));
fsModel
here can be something like view->model()
.
This is going to select and click the first item:
ui->ListWidget->setCurrentRow(0);
QListWidgetItem* item = ui->ListWidget->item(0);
ui->ListWidget->itemClicked(item);
Have you tried connecting the QListView singal:
void clicked ( const QModelIndex & index )
to a slot and reading the data from the
QModelIndex::data
It will provide the index, check if its the first one, if it is, set it.