QCustomPlot Discussion and Comments

Issue: two QCustomPlot widgets reading data from each otherReturn to overview

I have two widgets subclassing QCustomPlot and basically copying the financialchartsdemo and simpledemo.
Candle header:

class Candle : public QCustomPlot
{
    Q_OBJECT
public:
    Candle(QWidget *parent = Q_NULLPTR);
    ~Candle();
public:
    QCPFinancial *ohlc;
private:
    Ui::Candle ui;
};

Candle source:
Candle::Candle(QWidget *parent)
    : QCustomPlot(parent)
{
    ui.setupUi(this);
    this->setOpenGl(true);
    this->legend->setVisible(true);
    ohlc = new QCPFinancial(this->xAxis, this->yAxis);
    ohlc->setName("OHLC");
    ohlc->setChartStyle(QCPFinancial::csCandlestick);
    ohlc->setTwoColored(true);
    this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
}
Candle::~Candle()
{
}

Line header:
class Line : public QCustomPlot
{
    Q_OBJECT
public:
    Line(QWidget *parent = Q_NULLPTR);
    ~Line();
public:
    QCPGraph *graph_line;
private:
    Ui::Line ui;
};

Line source:
Line::Line(QWidget *parent)
    : QCustomPlot(parent)
{
    ui.setupUi(this);
    this->setOpenGl(true);
    graph_line = new QCPGraph(this->xAxis, this->yAxis);
    graph_line->setChannelFillGraph(0);
    graph_line->setBrush(Qt::NoBrush);
    graph_line->setAdaptiveSampling(true);
    graph_line->setPen(QPen(Qt::red, 0.5));
    this->xAxis2->setVisible(true);
    this->xAxis2->setTickLabels(false);
    this->yAxis2->setVisible(true);
    this->yAxis2->setTickLabels(false);
    connect(this->xAxis, SIGNAL(rangeChanged(QCPRange)), this->xAxis2, SLOT(setRange(QCPRange)));
    connect(this->yAxis, SIGNAL(rangeChanged(QCPRange)), this->yAxis2, SLOT(setRange(QCPRange)));
    this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
}

Line::~Line()
{
}

main source:
void onSomeSignalsReceived(){
    //------------------------------------------------------
    std::vector<double> x_d(idx.begin(), idx.end());
    std::vector<double> y_d(val.begin(), val.end());
    QVector<double> x = QVector<double>::fromStdVector(x_d);
    QVector<double> y = QVector<double>::fromStdVector(y_d);
    ui.linePlot->graph_line->setData(x, y);
    ui.linePlot->graph_line->rescaleAxes();
    ui.linePlot->replot(QCustomPlot::rpQueuedReplot);
    //------------------------------------------------------
    std::vector<double> o_d(m_o.begin(), m_o.end());
    std::vector<double> h_d(m_h.begin(), m_h.end());
    std::vector<double> l_d(m_l.begin(), m_l.end());
    std::vector<double> c_d(m_c.begin(), m_c.end());
    QVector<double> o = QVector<double>::fromStdVector(o_d);
    QVector<double> h = QVector<double>::fromStdVector(h_d);
    QVector<double> l = QVector<double>::fromStdVector(l_d);
    QVector<double> c = QVector<double>::fromStdVector(c_d);
    std::vector<double> t_d(c_d.size());
    std::iota(std::begin(t_d), std::end(t_d), 0);
    QVector<double> t = QVector<double>::fromStdVector(t_d);
    ui.candlePlot->ohlc->setData(t, o, h, l, c);
    ui.candlePlot->ohlc->rescaleAxes();
    ui.candlePlot->replot(QCustomPlot::rpQueuedReplot);
    //------------------------------------------------------
}

It works perfectly, like
https://i.imgur.com/rfO49Uk.png
but when any key is pressed or mouse is clicked, it becomes
https://i.imgur.com/BVwLQEr.png
or
https://i.imgur.com/jaLXNsD.png
What did I do wrong? Thanks in advance.

I find out that when setOpenGl is set to false, everything is working as expected, but when it's turned on, the problem shows up. I still don't know how to fix it since I have to turn on opengl support due to performance consideration.

Hi Tobias

Try the patch proposed by Pramod. Look here :

QCustomPlot OpenGL issues (setOpenGL true) by Mirza

For me, this patch fixed actifact display with OpenGL but performance stay low (more or less same that without OpenGL).

Thanks BCO, it works.