PDA

View Full Version : [QT4] QTreeView and expandable nodes



KShots
17th March 2006, 16:40
Is it possible to make a node marked as "expandable" if the model does not (yet) have any data loaded on that node?

What I'd like to do is set up a signal/slot connection to the view's expand() signal to tell the model to look up data for a given node.

I'd like to do this because looking up all the data at once takes several seconds, so taking in pieces of the data as needed should take significantly less time.

Currently, if there's no data under a node, there is no '+' symbol to click on. Can this behaviour be changed?

fullmetalcoder
17th March 2006, 16:58
ugly workaround but should work : create an empty model item prevent from doing a real expanding while no other item is added and remove it when another item is added (you've got to subclass QTreeView I guess...)

KShots
17th March 2006, 17:40
Yeah... currently, what I have is that there's a "placeholder" model item that's blank. When expanded, the model gets the expand signal. If it detects the placeholder, it removes it and inserts all the appropriate data. It only inserts the placeholder if it detects that a given node would have at least one element, so I don't get expandable nodes when there's no data under them.

I didn't have to subclass the view (thankfully). I just connected the view's expanded signal to my model's [/b]slotNodeExpanded[/b] slot.

It is kinda ugly, but at the moment it gets the job done properly. I was hoping to find a more elegant solution :).

wysota
17th March 2006, 17:52
You could subclass the delegate and introduce a custom role which would say if an "expand indicator" should be drawn, but unfortunately the tree view is the object responsible for drawing them, so it's obviously a limitation of interview.

In short words -- you can't do it "the right way".