How to get changechange event in Qt

I have a class inherited from QWidget, now in this class I will create an object QListViewand populate the elements for viewing. When the selection of items in the list view changes, I want to receive an event selectionChange.

How can i achieve this? Please tell me briefly.

+7
source share
2 answers

When you have a view, you will have a model that will be used to select the item. He is called QItemSelectionModel.

For example, with, QListViewyou can get selectionModel as follows:

QItemSelectionModel* selectionModel() const;

Now, with this model, you can connect to 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 )

, !

+10

https://doc.qt.io/archives/qt-4.8/qlistwidget.html , QListWidget view, , , .


https://doc.qt.io/archives/qt-4.8/qlistwidget.html#itemSelectionChanged , .

:

 private slots:
     void selChanged();

, . - - , QWidget.

 connect(yourListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(selChanged()));

0

All Articles