June 14, 2011

thuanvh thuanvh
Lab Rat
2 posts

How to display a tree by using Qt


Hi all,
I’m newbie with qt. I don’t know how to display a tree like the following image.


Which graphic library that we will use? And how to use it?
Thank any suggestion.

4 replies

June 14, 2011

Eddy Eddy
Area 51 Engineer
1571 posts

Looks like the elastic nodes example :
Link [developer.qt.nokia.com]


Qt Certified Specialist
Nokia Qt Ambassador

June 14, 2011

Iktwo Iktwo
Lab Rat
62 posts

I don’t know about a graphic library for painting trees but you could try to do it yourself, maybe defining levels.. dynamic arrays of dynamic arrays, and you then when you know how many items are on each level you can draw points like 1=0, 2=30,3=60..

  1. for (int var=0;var < level[1].count;var++){
  2.     //DRAW item(30,var*30)
  3. }

What I’m trying to say is that you can move 30px every time you draw a new item.

and to draw the lines I thnik that you could use the example elastic nodes.. hope that helps..

June 14, 2011

Andre Andre
Robot Herder
6663 posts

GraphViz [graphviz.org] comes to mind. Not really a Qt related question though, if you ask me.

June 14, 2011

jim_kaiser jim_kaiser
Lab Rat
144 posts

Um.. well.. it depends on what you have already. If you have the parent/child relationship in a datastructure (a C++ tree).. and your own algorithm to spread them out in a way it looks good.. then you can just use QPainter’s drawPoint() and drawLine() or a QPainterPath. But if you need a framework which you can use to automagically generate the points visually for the tree.. I don’t think Qt provides it.

  ‹‹ [Re-opened] Crashing application when trying to show popup window when moving focus to a date widget (KMyMoney) on MacOSX      Can Qt host WPF controls? ››

You must log in to post a reply. Not a member yet? Register here!