c++qtqt5qtchartsqchart

qt get child (Callout) from QChart


I implemented a custom Callout class like in this example Callout Example

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

If I have only access to chart (callout went out of scope), how can I regain access to callout. I thought about using

QObjectList children = chart->children();

but callout is not here. How can I get access to callout again?


Solution

  • you have to use childItems(), this returns the QGraphicsItems children.

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