PDA

View Full Version : Hide the branches in a QTreeWidget



SkripT
7th March 2006, 12:31
Hi all, as the post says I want to hide the branches in a QTreeWidget. I attach an image showing the result that I want. I think that the solution could be calling QTreeView::drawBranches but I don't know how to make it. Anybody knows it?

Thanks.

jpn
7th March 2006, 12:36
You mean expanding/collapsing?


void QTreeWidget::setItemExpanded (http://doc.trolltech.com/4.1/qtreewidget.html#setItemExpanded) ( const QTreeWidgetItem * item, bool expand)

SkripT
7th March 2006, 12:42
You mean expanding/collapsing?

No, I mean not to draw the branches joining each item in the tree view with its parent

jpn
7th March 2006, 13:25
No, I mean not to draw the branches joining each item in the tree view with its parent
Ah of course, sorry for being so thoughtless.

Yes, reimplementing drawBranches() and leave it empty.

SkripT
7th March 2006, 15:24
Many thanks jpn

SkripT
8th March 2006, 10:12
Hi again, I've reimplemented drawBranches leaving it empty and the branches are not drawn (as I wanted), the problem is that the icons to expand/colapse the tree items aren't neither painted :( but in the example that I have attached are painted. Anybody knows how to force to paint them withoyt having to draw the branches?

jpn
8th March 2006, 11:31
In that case you most probably need to implement your own style which can draw that kind of primitive elements the way you want (QStyle::PE_IndicatorBranch).

SkripT
8th March 2006, 15:14
Ok thanks jpn, but, and sorry for my ingnorance, how could I call to paint the QStyle::PE_IndicatorBranch directly (if it's possible to do it)?

jpn
8th March 2006, 15:54
Mom, look what I did!! Heh, this was kinda interesting so I gave it a shot. Never played too much with styles...

Create an instance of the attached style and set it for your treewidget (QWidget::setStyle(QStyle*)).
And remember to remove the empty drawBranches() from your treewidget..

SkripT
8th March 2006, 18:16
Looks cool jpn, it's exactly what I need. Thanks a lot one more time.

josh
3rd April 2007, 21:09
This helped us (http://www.soph-ware.com/) too, thanks.

sawarsi
4th October 2012, 20:28
jpn,

this is really good and exactly what i wanted so thanks for this. is there anyway to modify your code so that the collapse/uncollapse indicator is drawn in the style seleted for the app? say for instance, i am running on KDE and want the indicator to be the same as what is used in all the other apps - is that possible?

wysota
4th October 2012, 20:38
You can always use a style proxy (QProxyStyle).

sawarsi
4th October 2012, 21:23
but his current implementation of drawPrimitive draws the windows standard + and - for collapsed/expanded. how to modify the drawPrimitive function to draw the appropriate indicator? do you think it would be easier to simply set and icon with on/off properties and display those instead but this would give a common look on all platforms.

wysota
4th October 2012, 21:32
how to modify the drawPrimitive function to draw the appropriate indicator?
You ask the style for the primitive.

sawarsi
4th October 2012, 21:37
can you send a line of code that would do that? i am not sure what to query for.

wysota
4th October 2012, 22:10
can you send a line of code that would do that?
I left it in my other pants :)

And seriously, Qt's source code is available for download, take it, see what QTreeView does to draw the branches and you'll see the exact calls you need to make.

d_stranz
4th October 2012, 22:40
I left it in my other pants :)

Oh, I hate it when that happens. You get all the way in to work, reach in your pocket for that line of code you wrote last night at home, and then you realize you wore a different pair of pants yesterday. :mad:

sawarsi
5th October 2012, 14:21
it's ok thought i would ask before diving into the code. qt has changed a lot since 1998-2001 when i used it extensively for commercial and non-commercial use and the code base has become so big it is hard to figure things out especially when there is multiple inheritance. it sure was a lot simpler back then to get the desired results by studying the code.

wysota
7th October 2012, 16:57
Have a bite :)

http://qt.gitorious.org/qt/qt/blobs/4.8/src/gui/itemviews/qtreeview.cpp