[Qt-interest] Catching row changes of QListView

Malyushytsky, Alex alex at wai.com
Mon May 16 05:39:22 CEST 2011


I have not followed discussion, but you don't need to override anything to get signal that selection is changed:

#include <QItemSelectionModel>
#include <QItemSelectionModel>

.....
QListView* listView = ......

connect (listView->selectionModel(),  selectionChanged ( const QItemSelection &, const QItemSelection &),
         this, mySlot ( const QItemSelection &, const QItemSelection &)

.............

MyCLass::mySlot( const QItemSelection & selected, const QItemSelection & unselected )
{
// here you have indexes:
        QModelIndexList selectedIndexes  = selected->indexes ();
        QModelIndexList unselectedIndexes  = unselected ->indexes ();

}

Also you can connect to protected or even private slot, you just can't call it directly.
Basically Qt allows you to ignore access restrictions and call all protected and private slots by connecting it to the signal (you always can create a QObject subclass and emit signal ).

Regards,
        Alex

-----Original Message-----
From: qt-interest-bounces+alex=wai.com at qt.nokia.com [mailto:qt-interest-bounces+alex=wai.com at qt.nokia.com] On Behalf Of Andreas Pakulat
Sent: Saturday, May 14, 2011 1:44 PM
To: qt-interest at qt.nokia.com
Subject: Re: [Qt-interest] Catching row changes of QListView

On 14.05.11 14:17:36, Robert Hairgrove wrote:
> There is a protected signal "selectionChanged(...)" of QAbstractItemView
> which would be nice to connect to a slot in order to update some other
> controls in a data input form I am creating.

No there's not. There's a protected slot which subclasses can use but
you can't connect to that anyway.

On the other hand, all signals declared are protected functions (thats
what the signals macro does) and you can still connect to it...

> Unfortunately, QListView doesn't seem to provide any mechanism for
> detecting the user's change of selection. Do I need to subclass
> QListView in order to connect with this signal, or is there a better (or
> easier) way?

As was already said, use the itemselection model, that supplies you with
all modification information.

Andreas

_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”


More information about the Qt-interest-old mailing list