1

I need to draw a tree with Qt,

I was thinking using QGraphicsScene and QGraphicsItem for the nodes. But as I want the nodes to be movable, so how do it the best way for the lines between the node ?

Any suggestions ?

Thx.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134

2 Answers2

1

I would implement arcs as items as well, QGraphicsLine item in particular. The line could go between the centers of connected nodes. Keep a reference to incident edges in the node item, and during node dragging update line nodes with:

edge->setLine(QLineF(node_center.x, node_center.y);
Masci
  • 5,864
  • 1
  • 26
  • 21
1

I suggest you use QML for drawing those kind of things (I hate QML language, but unfortunately it is the future in Qt for drawing high performance graphics, they are working hard on that and Qt5 will also be more QML-centric I guess). For drawing lines you can use rotated thin rectangles. See Rectangle.

Luca Carlon
  • 9,546
  • 13
  • 59
  • 91