[Qt-interest] FW: QAbstractItemModel: Hiding rows

Eric Clark eclark at ara.com
Thu Jul 9 22:46:51 CEST 2009


Arnold, sorry about the direct response, I forgot to change the to address when replying. :)

-----Original Message-----
From: Eric Clark 
Sent: Thursday, July 09, 2009 3:45 PM
To: 'Arnold Krille'
Subject: RE: [Qt-interest] QAbstractItemModel: Hiding rows

This is not "simply" a removal of rows. My model is setup to get its information from a hierarchial tree structure already defined by a different object in my application. The other object always has these items in its list of children, no matter if they are hidden or not. The "hidden" part is only a GUI preference because some of the objects are not to be shown in the TreeView, but they are still there. Removing the rows would cause very bad bugs, since the rowCount always returns the number of children and the ability to get a child by row number would be screwed up because I would have to index things based on their visibility, not their existence in the children array. Not exposing it via the model is not an option as that would make my life very difficult. I would have to reorder indexes all the time, and have to have lots of extra code.

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Arnold Krille
Sent: Thursday, July 09, 2009 2:46 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QAbstractItemModel: Hiding rows

Hi,

On Thursday 09 July 2009 21:23:05 Eric Clark wrote:
> Is anyone aware of a way to tell the QAbstractItemViews that a row is 
> hidden in the QAbstractItemModel from the model class? I know you can 
> hide the row from the view, but I would like to be able to tell the 
> view it is hidden from the model, like as a part of the flags or something.

Hiding a row (or column) in the model is "simply" a matter of removeRows() and removeColumns(). The model is only a representation of the data to show. So there is no hiding. Only not exposing it via the model.

There is a way to hide stuff without modifying your model: Use a proxy-model on top to hide (ie. not expose) your rows/columns. Then all the views attached to that proxy will get the filtered data.

Have fun,

Arnold




More information about the Qt-interest-old mailing list