[Qt-interest] QTreeView expanding: don't offer individual controls for nested items

Stephen Kelly steveire at gmail.com
Thu Jan 6 22:52:10 CET 2011


Jan Kundrát wrote:

> Hi,
> I'm writing an e-mail viewer [1] and would like to modify the QTreeView
> to handle threading "better". Right now, when a thread gets too deep,
> the recent messages could easily be hidden in many levels of nesting,
> and one would have to click through quite a lot of items in order to
> finally reach the recent ones. On the other hand, being able to collapse
> uninteresting threads is a handy feature. That's why I like
> Thunderbird's GUI which displays the expanding/collapsing control just
> for the top-level items (ie. in Qt interview speak, for those having an
> invalid index as their parent). I'd like to do something similar in Qt.
> 
> I was thinking about reimplementing QTreeView::drawBranches(). If I did
> that (it's a 100+ lines function, though), I'd have no indicators, but
> mouse clicks would still work; it looks like mouse event handlers are
> rather tied with QTreeViewPrivate, and that's where my library-user
> abilities end. I'd also have to properly listen for expanded() on a
> top-level item etc, but that's trivial; I think that the biggest
> obstacle is disabling mouse controls for the "always expanded if parent
> expanded" items.
> 
> So, any idea about how to make items whose parent is not an empty
> QModelIndex always expanded?

Install an event filter and filter out events which would collapse them, 
like clicks, double click, pressing '-' and pressing left, and you would 
have to set autoExpandDelay to false so that they can't be collapsed during 
drags.


> 
> Cheers,
> -jkt
> 
> [1] http://trojita.flaska.net/
> 





More information about the Qt-interest-old mailing list