[Qt-qml] QML/C++ shared QItemSelectionModel

Carl Snellman carl.snellman at gmail.com
Wed Sep 15 19:10:07 CEST 2010


Hey Stephen,

and thanks for help!

Clearly this seems to be something that is not yet though of, so I'm
hoping this gets fixed in the future.

I'll try the approach you proposed.

Thanks,
Carl

On Tue, Sep 14, 2010 at 7:16 AM, Stephen Kelly <steveire at gmail.com> wrote:
> Carl Snellman wrote:
>
>> Hey,
>>
>> I have one common QAbstractItemModel that serves data for a ListView
>> in QML side and for another QGraphicsWidget (a map that shows items).
>> They use the same data model nicely, but as my goal is to keep the
>> selection in sync in both views, so I'm trying to get them to share
>> the selection model, too. My problem is that I cannot find a way to
>> get those two views to share the same selection model
>> (QItemSelectionModel, acquired with map.selectionModel()). Would
>> anyone have any suggestions/snippets how to hook my own
>> QItemSelectionModel to QML's ListView?
>>
>>
>> Any help is greatly appreciated!
>> Carl
>
>
> I agree. QML should definitely make some use of QItemSelectionModel or at
> least decouple selection from the view (I'm not sure if it does that at
> all).
>
> My solution is a wrapper around a QItemSelectionModel with some slots:
>
> public slots:
>  void clearSelection();
>  void select(int row, int command);
>
> I had to make command an int because there was so way to use
> QItemSelectionModel::SelectionFlags at the time. I don't know if that has
> changed.
>
> I also needed some Connections{} elements in the QML. There should
> definitely be something built in though, as I spent some time trying to
> convince some trolls of :).
>
> All the best,
>
> Steve.
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
>




More information about the Qt-qml mailing list