[Qt-interest] Creating a QModelIndex outsideof a QAbstractItemModel subclass

Dario Ahdoot dario.ahdoot at image-metrics.com
Fri Mar 13 00:33:45 CET 2009


Here you go. This should replicate the issue. I did notice that if you pass in QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows instead of just QItemSelectionModel::ClearAndSelect to the select method that it will select the whole row. However, you should not need to do this IMHO if the tree has a selection behavior of SelectRows.

Dario

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Scott Aron Bloom
Sent: Thursday, March 12, 2009 1:43 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Creating a QModelIndex outsideof a QAbstractItemModel subclass

Dario...

Please package up a "complete" reproducible example.

The "bug" could exist in the view, the creation of the view, the model,
the index creator etc etc...

Scott

> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Dario Ahdoot
> Sent: Thursday, March 12, 2009 11:51 AM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Creating a QModelIndex outsideof a
> QAbstractItemModel subclass
> 
> Here is what I want to do, which is currently not selecting the whole
row:
> 
> someAbstractViewPointer->selectionModel()->select(
someAbstractModelPointer-
> >index( 5, 1 ), QItemSelectionModel::ClearAndSelect );
> 
> In the example above, the view should highlight all of row 5, even
though the
> index I pass in is for column 1.
> 
> Thanks,
> Dario
> 
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Scott Aron Bloom
> Sent: Thursday, March 12, 2009 11:43 AM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Creating a QModelIndex outsideof a
> QAbstractItemModel subclass
> 
> It should...  If you call the models "set current" then its model
> specific...
> 
> But if you call the selection model from a view, it should (and does
for
> me) select the row...
> 
> Make sure your selection data is correct
> 
> Scott
> 
> > -----Original Message-----
> > From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> > bounces at trolltech.com] On Behalf Of Dario Ahdoot
> > Sent: Thursday, March 12, 2009 11:18 AM
> > To: qt-interest at trolltech.com
> > Subject: Re: [Qt-interest] Creating a QModelIndex outsideof a
> > QAbstractItemModel subclass
> >
> > Yes, it doesn't select the whole row. However, if a view's style is
> select the
> > whole row, then selecting an index through the selection model of
the
> view
> > should be identical to selecting that index through the UI itself,
no?
> i.e.
> > the whole row of the index should be selected, I would think.
> >
> > If you select an item in a tree view where the selection behavior is
> to select
> > the whole row when you click on an item (or select it
> programmatically), it is
> > weird to see the existing behavior, both from a coders and UI point
of
> view.
> >
> > D
> >
> > -----Original Message-----
> > From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> > bounces at trolltech.com] On Behalf Of Andreas Pakulat
> > Sent: Thursday, March 12, 2009 9:09 AM
> > To: qt-interest at trolltech.com
> > Subject: Re: [Qt-interest] Creating a QModelIndex outside of a
> > QAbstractItemModel subclass
> >
> > On 12.03.09 10:36:05, Dario Ahdoot wrote:
> > > Thanks. I somehow missed that method on QAbstractItemModel.
> > >
> > > On a related note, based on the code snippet below, would you
> consider it a
> > bug that if you have a tree with a SelectionBehavior of
> > QAbstractItemView::SelectRows, then when you call select on it, then
> it should
> > select the whole row of the model index you pass in?
> >
> > So you mean it doesn't select the whole row, right? Thats actually
> correct,
> > because you're selecting something in the selection model, not the
> view.
> > The selection behaviour is private to the view and only drives what
> the
> > user can select. For example its perfectly possible to have the same
> > selection model in two different views and one only allows to select
> full
> > rows, while the other allows to select single items (no I don't have
a
> real
> > world use-case at hand right now).
> >
> > Andreas
> >
> > --
> > A few hours grace before the madness begins again.
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SelectionTest.zip
Type: application/x-zip-compressed
Size: 2315 bytes
Desc: SelectionTest.zip
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090312/c48e2dba/attachment.bin 


More information about the Qt-interest-old mailing list