Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to display a tree by using Qt
Forum Updated to NodeBB v4.3 + New Features

How to display a tree by using Qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 4.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thuanvh
    wrote on last edited by
    #1

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

    !http://reference.wolfram.com/mathematica/ref/Files/TreePlot.en/O_1.gif(Tree)!

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

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Looks like the elastic nodes example :
      "Link ":http://developer.qt.nokia.com/doc/qt-4.7/graphicsview-elasticnodes.html

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Iktwo
        wrote on last edited by
        #3

        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..
        @
        for (int var=0;var < level[1].count;var++){
        //DRAW item(30,var*30)
        }@

        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..

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          "GraphViz":http://www.graphviz.org/Documentation.php comes to mind. Not really a Qt related question though, if you ask me.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jim_kaiser
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved