How to get the selectionchange event in Qt

nokia, qt, qt4, symbian

Solution

When you have a view, you will have a model that will be used to select item. It's called a `QItemSelectionModel`.

For example, with your `QListView`, you can get the selectionModel this way :

QItemSelectionModel* selectionModel() const;

Now, from that model, you'll be able to connect on many signals :

void currentChanged ( const QModelIndex & current, const QModelIndex & previous )
void currentColumnChanged ( const QModelIndex & current, const QModelIndex & previous )
void currentRowChanged ( const QModelIndex & current, const QModelIndex &    previous )
void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )

I think it will help you a bit!

Problem

I have a class inherited from `QWidget`, now in that class I will be creating a`QListView` object and filling up the items to view. When the selection of items in the list view gets changed, I want to get the `selectionChange` event. How can I achieve this?. Please tell me in brief.

Original source