Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to acess PieSlice in Backend?
Qt 6.11 is out! See what's new in the release blog

How to acess PieSlice in Backend?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 406 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zrrr1
    wrote on last edited by zrrr1
    #1

    I have to acess a PieSlice that is in a PieSeries in a ChartView.
    The pieSlcie has objectName and i use this code to trie to acess this->slice = engine->rootObjects().at(0)->findChild<QObject*>("graf"); but i can't. Can someone help me? 0_1528555123803_Capturar.PNG

    1 Reply Last reply
    0
    • KillerSmathK Offline
      KillerSmathK Offline
      KillerSmath
      wrote on last edited by KillerSmath
      #2

      @zrrr1
      Hi there.

      I googled about this problem and found an old topic about ChartView Binding to C++ Data
      https://forum.qt.io/topic/74675/qml-chartview-binding-to-c-data/6

      You can get the ChartView object and call the series function and return an object of type AbstractSeries. Then, convert him to QpieSeries type and finally you have all acess of pieS object.

      Below is a code demonstrating it:

      #include <QAbstractSeries>
      #include <QPieSerieS>
      #include <qDebug>
      
      ...
          QObject *chartView = engine.rootObjects().at(0)->findChild<QObject *>("graf");
      
          QtCharts::QAbstractSeries* absSeries;
      
          QMetaObject::invokeMethod(chartView, "series", Qt::AutoConnection, Q_RETURN_ARG(QtCharts::QAbstractSeries*, absSeries), Q_ARG(int, 0)); // get the first serie of chart (QML)
      
          QtCharts::QPieSeries *pieSeries = qobject_cast<QtCharts::QPieSeries *>(absSeries); // convert to QPieSeries
      
          foreach(QtCharts::QPieSlice* slice, pieSeries->slices()){
              qDebug() << "Label Name -> " + slice->label();
          }
      ...
      

      @Computer Science Student - Brazil
      Web Developer and Researcher
      “Sometimes it’s the people no one imagines anything of who do the things that no one can imagine.” - Alan Turing

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved