[SOLVED]How to click the first row in Qlistview by default ?
I have some items in the qlistview . I want the first row to be clicked by default (no column in listview)
i have used signal clicked if the user click the items . But i want item0 to be clicked by default.
Do you mean selected ? If so use QItemSelectionModel::select
You can retrieve the selection model directly from your QListView.
Hope it helps
Thanks for the reply
It will just select the item0.
My signal clicked will not trigger by default.
You can invoke the signal as a event.
QMetaObject::invokeMethod(ui->listView_Messages, "clicked", Qt::QueuedConnection, Q_ARG(QModelIndex, QModelIndex()));
The correct way to select an item is using the selection model. The clicked signal is emitted on mouse interaction.
Thanks for the reply.
I tried invoke the signal as a event as you mentioned but did not work for me.
Should i add index of the model which is set to list-view ? If so how to include?
This did not work for me .
QModelIndex Index= ui->listView_Messages->model()->index(0,0); ui->listView_Messages->selectionModel()->select( Index, QItemSelectionModel::Select );
Did i miss anything?
Silly question but is Index valid ?
Have set the listview to model and fetched the index from model.