[Solved] Signal when a QListView selection changes due to keyboard activity?
-
I have a QDialog, created with QT Designer, that looks like so:
!http://i.imgur.com/1XdmGvT.png()!The list of servers on the left is a QListView with a QStringListModel. Mouse clicking an item in the list view updates the form with the information for the selected item by connecting the view’s activated(QModelIndex) signal to a slot function in the dialog.
However, pressing up or down on the keyboard also changes the selected item, but no signal is emitted, so the form isn't updated to match the selected item. How can this be fixed?
I'm using Qt5
-
Hi DrTwox!
For this cases you should use QItemSelectionModel signals.
@QItemSelectionModel *selectionModel = ui->listView->selectionModel();
connect(selectionModel,SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this,SLOT(rowChangedSlot(QModelIndex,QModelIndex)));@ -
Oops, I did have that wrong! Thanks.
However, now the runtime can't find the slot function. What should it look like? I have:
@void ConnectionDialog::rowChangedSlot( const QModelIndex& selected, const QModelIndex& deselected ) {}@
... but at runtime I getQObject::connect: No such slot ConnectDialog::rowChangedSlot(QModelIndex,QModelIndex)
Here's the connect call:
@connect( serverListView->selectionModel(), SIGNAL( currentRowChanged(QModelIndex,QModelIndex)), this, SLOT( rowChangedSlot(QModelIndex,QModelIndex) ) );@