在 Qt 中以图形方式表示树节点的最佳方式

发布于 2024-09-19 10:07:11 字数 126 浏览 1 评论 0原文

我正在尝试在 Qt 中可视化一棵树。

到目前为止,我的所有节点都由简单的圆圈组成并基于 QGraphicsItem 类。但我需要在每个节点上显示一些文本,如何将 QLabel“附加”到我的节点?

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦亦如幻 2024-09-26 10:07:11

您可以在节点上使用QGraphicsTextItem

QGraphicsTextItem *nodeText = new QGraphicsTextItem("TEXT LABEL", nodeItem);

You can use a QGraphicsTextItem on your nodes.

QGraphicsTextItem *nodeText = new QGraphicsTextItem("TEXT LABEL", nodeItem);
起风了 2024-09-26 10:07:11

那么,为什么不使用 QTreeView 来查看你的树呢?您只需必须使用自己的模型对 QAbstractItemModel 进行子类化并使用它。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文