I am trying to figure this out and it seems to me that I should use QItemSelectionModel, but I cannot find an example of how to connect things.
I defined in the .h file.
QItemSelectionModel* selectionModel;
Now in the view constructor, I install:
selectionModel = ui->treeView->selectionModel();
connect(ui->treeView->selectionModel(), SIGNAL( ui->treeView->selectionModel(const QModelIndex&, const QModelIndex &) ),
this, this->selectionChanged ( QItemSelection & sel, QItemSelection & desel) );
I thought there would be a predefined slot, but I cannot find it, so I added it (the syntax of which I found here )
void MyDialog::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
{
qDebug() << "Item selection changed";
}
I also tried replacing QItemSelection with QModelIndex, but it still doesn't work.
What do I need to do to just get notified when the selection has been changed, and obviously grab the newly selected item?
source
share