[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.connect(ui->listView_Messages,SIGNAL(clicked(QModelIndex)),this,SLOT(listViewClicked(QModelIndex)));
-
Hi,
Do you mean selected ? If so use QItemSelectionModel::select
You can retrieve the selection model directly from your QListView.Hope it helps
-
@SGaist
Thanks for the reply
It will just select the item0.
My signal clicked will not trigger by default. -
Hi
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.
-
@Devopia
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? -
@SGaist
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 ?
-
@SGaist
Have set the listview to model and fetched the index from model.