0

I am using Qt5.9.6 and when changing QChart axis ranges background is not updated. As soon as other application is chosen to be active background is updated.

enter image description here

after range change

enter image description here

Any idea ? Thanks


I tried to create a representative example of my application but the example (unfortunately) works.

#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QScatterSeries>
#include <QtCharts/QChart>
#include <QtCharts/QValueAxis>
#include <QDebug>
#include <qslider>
#include <QLayout>
#include <qwidget>
#include <QtMath>
#include <QApplication>

QT_CHARTS_USE_NAMESPACE

int main(int argc, char *argv[])
{
    QApplication         a {argc, argv};

    struct {
        const double nbr_of_per {5.5};
        // number of samples
        const int    nos        {(int)(nbr_of_per*200*M_PI)};
    } sine_params;

    const int      sld_max {sine_params.nos-1};
    const double       div {100.0};
    QSlider        *   sld {new QSlider{Qt::Horizontal}};
    QChartView     *  view {new QtCharts::QChartView{}};
    QChart         * chart {new QtCharts::QChart{}};
    QLineSeries       sine {};
    QScatterSeries   point {};

    sld->setRange(0, sld_max);
    chart->addSeries(&sine);
    chart->addSeries(&point);

//    for(auto e: chart->series())
//        e->setUseOpenGL(true);

    for(double i{}; i< sine_params.nos;i++)
        sine.append(QPointF{i/div, sin(i/div)});

    point.append(QPointF{});
    point.setMarkerSize(20);

    chart->legend()->hide();

    QValueAxis x_ax;
    x_ax.setRange(0, sine.pointsVector().last().x());
    x_ax.setTickCount(5);
    x_ax.setLabelFormat(QString{"%."+QString::number((int)log10(div))+"f"});
    chart->setAxisX(&x_ax, &sine);
    chart->setAxisX(&x_ax, &point);

    QValueAxis y_ax;
    y_ax.setRange(-1, 1);
    y_ax.setTickCount(5);
    y_ax.setLabelFormat("%.3f");
    chart->setAxisY(&y_ax, &sine);
    chart->setAxisY(&y_ax, &point);

    QFont font{chart->axisX()->labelsFont()};
    font.setPixelSize(20);
    chart->axisX()->setLabelsFont(font);
    chart->axisY()->setLabelsFont(font);

    view->setChart(chart);
    view->setRenderHint(QPainter::Antialiasing);

    QVBoxLayout * vl{new QVBoxLayout};
    vl->addWidget(view);
    vl->addWidget(sld);

    QWidget w;
    w.setLayout(vl);
    w.show();

    QObject::connect(sld, &QSlider::valueChanged,
        [=,&sine,&point](int val){
            QPointF p{val/div, sine.at(val).y()};
            point.clear();
            point.append(p);
            chart->axisX()->setRange(p.x()-(100/div), p.x()+(100/div));
            chart->axisY()->setRange(p.y()-(.1), p.y()+.1);
            // in my misbehaving application i have to use update() and only
            // then I do not get 'leftovers' after changing axis ranges
            // view->scene()->update(view->rect());
        }
    );

    return a.exec();
}

very annoying

francek
  • 492
  • 4
  • 11
  • Please provide some code that reproduces the problem. Most likely you’re doing something wrong, but I can’t reproduce the issue. What exact qt version is it (5.9.what)? – Kuba hasn't forgotten Monica Jan 16 '19 at 14:09
  • "can’t reproduce the issue" - neither can I Kuba, unfortunately. I found a workaround calling view->scene()->update(view->rect()); – francek Jan 17 '19 at 09:01
  • You might want to start a branch on your source control, and prune irrelevant code while verifying that it’s still broken and committing as you go. That way you’ll find what’s the critical detail. Also, for test cases, it suffices to `#include ` and perhaps ``. Those two will pull everything else for you. Also, in most cases the `#include ` form is incorrect as it postpones build tree musconfoguration to being caught only at the link stage. Unless the documentation specifically says otherwise, you should `#include ` without the module path prefix. – Kuba hasn't forgotten Monica Jan 17 '19 at 22:50
  • Thanks for the hints Kuba. I copied '#include ' from Qt framework examples and thought it is some interim necessity if they did it. "..it suffices to #include and perhaps ." - good to know. Interesting is when I tried it compile/link time was noticeably higher. – francek Jan 18 '19 at 08:41
  • The compile time will be higher, but it’s absolutely irrelevant in an example on stack overflow. Nobody will be compiling it multiple times, or at least sufficiently often to have it matter. * Qt examples must succeed being built with the rest of Qt framework, and thus they must follow the rules used within the Qt framework sources. Those rules are not the same as the ones for the user code that merely uses Qt. – Kuba hasn't forgotten Monica Jan 21 '19 at 14:13

0 Answers0