自定义 QQuickItem 中的文本 [英] Text in Custom QQuickItem

查看:63
本文介绍了自定义 QQuickItem 中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个自定义 QQuickItem,它应该能够制作线图(x vs y).出于性能原因,我使用 QSGNodes 做到了这一点.我想知道为 x-ticks 实现文本标签的最佳方法是什么(它们应该根据数据范围自动设置).

I am implementing a Custom QQuickItem which should be able to make a lineplot (x vs y). For performance reasons I did this using QSGNodes. I wonder what is the best way to implement the Text-Labels for the x-ticks (they should get set automatically according to the data range).

我应该使用 QQuickPaintedItem 还是有办法通过 QQuickItem 来实现?

Should I use a QQuickPaintedItem or is there a way to do it via the QQuickItem?

或者是否可以动态创建文本qml类型(http://doc.qt.io/qt-5/qml-qtquick-text.html) 在我的 C++ 文件中?

Or is it possible to dynamically create text qml types ( http://doc.qt.io/qt-5/qml-qtquick-text.html) in my c++ file?

推荐答案

不要通过重新发明轮子使事情变得过于复杂.QML 已经有 Text 类型.

Don't over-complicate things by reinventing wheels. QML already has a Text type.

有一个缺点 - 决定没有公共 API 来以 C++ 形式使用来自 C++ 的 QML 类型.而且我不建议从 C++ 创建 QML 对象,这只会适得其反.

There is a downside - the decision to not have a public API to use the QML types from C++ in their C++ form. And I would not recommend creating QML objects from C++, it is just counterproductive.

这意味着您的自定义 QML 类型不会完全用 C++ 实现,您可以在 C++ 中实现核心"内容,并且仍然在 QML 端组合完整的类型,您还可以在其中使用绑定、锚点、模型、定位器、动态作用域以及所有在 C++ 中很难做到的好东西.

Which means that your custom QML type will not be implemented purely in C++, you can implement the "core" stuff in C++ and still compose the complete type on the QML side, where you also get to use bindings, anchors, models, positioners, dynamic scoping and all that good stuff that is hard to do in C++.

这种情况并不少见,许多库存 QML 控件都是以这种方式实现的 - 一个暴露于 QML 的抽象 C++ 核心,在那里它以 QML 语法完成为一个完整的控件.

This is not uncommon, lots of the stock QML controls are implemented this way - an abstract C++ core exposed to QML, where it is finished into a complete control in QML syntax.

这篇关于自定义 QQuickItem 中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆