Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the selectionchange event in Qt

I have a class inherited from QWidget, now in that class I will be creating aQListView 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.

like image 332
Naruto Avatar asked Mar 18 '10 09:03

Naruto


1 Answers

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!

like image 71
Andy M Avatar answered Nov 09 '22 18:11

Andy M