PDA

View Full Version : Drawing inside Widget



Bobruisk
2nd May 2013, 16:26
Hi!

I have a tree structure that I want to display inside a widget:



. A
/ \
B C
/ \
D E


Here, each node (A...E) are represented by a widget containing some data about the node. These nodes are all drawn inside another QWidget, let's call it Parent, which acts similarly to a main window.

I have managed to create and layout the nodes nicely, but I would also like to create the edges between them. Right now, my tree display looks like:



. A

B C

D E


I'd like to hear from some experienced forum user; what is the best approach to draw these lines? I have found no "raw" drawing tools inside a QWidget (the Parent). Basically, if I could create an "EdgeWidget" that points from x1,y1 to x2,y2, I would be all set. But how do I create such a widget?

Thanks!

//Bobruisk

wysota
2nd May 2013, 19:48
Your approach of making each node a separate widget is wrong. Either draw everything (all nodes and all edges) in a single widget or use QGraphicsView where you'll be able to represent each node and each edge as a separate object. "Elastic Nodes" example can help you with that approach.

Bobruisk
3rd May 2013, 08:32
I will look into that, thank you!

//Bobruisk