June 14, 2011

thuanvh thuanvh
Lab Rat
4 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.

Tree

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
1563 posts

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

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

June 14, 2011

Iktwo Iktwo
Lab Rat
73 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
6296 posts

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

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

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!