views:

54

answers:

2

Hello,

I'm trying to visualise a tree in Qt.

So far, all my nodes consist of simple circles and based on QGraphicsItem class. But I need to display some text over every node, how can I "attach" a QLabel to my nodes?

Thanks in advance.

A: 

Well, why don't you use QTreeView to view your tree ? You just have to subclass QAbstractItemModel with your own model and use it.

tibur
Sorry, I should have used term "graph" instead of "tree". I'm trying to achieve something like "elastic nodes" example in the Qt demo.
frbry
+1  A: 

You can use a QGraphicsTextItem on your nodes.

QGraphicsTextItem *nodeText = new QGraphicsTextItem("TEXT LABEL", nodeItem);
Arnold Spence
Yep, I solved my issue by doing what you said. Although I've figured it out by myself, I will accept this as an answer.
frbry