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. Qt5 - chartView->grab() doesn't capture child elements
Forum Updated to NodeBB v4.3 + New Features

Qt5 - chartView->grab() doesn't capture child elements

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.1k 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.
  • D Offline
    D Offline
    DFRM
    wrote on last edited by p3c0
    #1

    I'm trying to plot data in a QLabel widget using bar chart format. After the chart is created, I capture it using chartView->grab() for insertion into the QLabel. This approach works with a pie chart, but for a bar chart the child elements (QBarSeries and QBarSet) are not displayed.

    The code is as follows:

    QT_CHARTS_USE_NAMESPACE
    
    QChartView* chartView = new QChartView();
    chartView->setRenderHint(QPainter::Antialiasing);
    
    QChart* chart = chartView->chart();
    
    QBarSeries *series = new QBarSeries();
    
    QBarCategoryAxis *categories = new QBarCategoryAxis();
    QBarSet *set0 = new QBarSet("test");
    set0->setBrush(Qt::blue);
    
    for (int i = 0; i < 20; ++i) {
        set0->append(static_cast<double>(10-std::abs(10-i)));
        categories->append(QString::number(i));
    }
    series->append(set0);
    
    chart->addSeries(series);
    chart->setAnimationOptions(QChart::SeriesAnimations);
    chart->setTitle("Plot Test");
    
    chart->setAxisX(categories, series);
    chart->createDefaultAxes();
    
    chart->legend()->setVisible(true);
    chart->legend()->setAlignment(Qt::AlignBottom);
    
    
    *m_chart = chartView->grab();
    

    This is the displayed image:

    0_1509676050861_barchart.png

    If instead, I do:

    chartView->show();

    A window pops up with QBarSeries data included. Any ideas on why the grab() method is not capturing the child elements?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      chart->setAnimationOptions(QChart::SeriesAnimations); that makes the series grow in an animation. you are probably capturing the first frame of that animation.

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • D Offline
        D Offline
        DFRM
        wrote on last edited by
        #3

        That was it. Removing the call to:

        chart->setAnimationOptions(QChart::SeriesAnimations);

        resolved the issue.

        Thanks!

        1 Reply Last reply
        0

        • Login

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