c++ - qt 从 QChart 获取子项(标注)

标签 c++ qt qt5 qtcharts qchart

我在这个例子中实现了一个自定义标注类 Callout Example

QPolarChart *chart = new QPolarChart();
Callout *callout = new Callout(chart);

如果我只能访问图表(标注超出范围),我如何才能重新获得对标注的访问权限。我考虑过使用

QObjectList children = chart->children();

但标注不在这里。 我怎样才能再次访问标注?

最佳答案

您必须使用 childItems(),这会返回 QGraphicsItem 的子项。

 for(QGraphicsItem *childItem: chart->childItems()){
     if(Callout *c = dynamic_cast<Callout *>(childItem)){
         //use c
     }
 }

关于c++ - qt 从 QChart 获取子项(标注),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51420994/

相关文章:

c++ - 派生类的切片是如何发生的?

c++ - `const shared_ptr<T>` 和 `shared_ptr<const T>` 之间的区别?

c++ - Qt 树模型与用于存储翻译字典的嵌套映射

c++ - 如何添加带有 QListView 项目的复选框?

qt - 如何在QML中声明列表属性

python - 通过文本输入添加新项目时,阻止 QScrollArea 项目跳跃

c++ - 在 XY 点数组中找到三个 XY 点的最大面积

macos - 在 macbook pro 上安装 PYQT5 后如何打开 QT Designer?

c++ - Linux 的 Qt 应用程序部署

c++ - 为什么我在使用 dynamic_cast 和模板时收到错误 "A is an inaccessible base of B"?