QCustomPlot Discussion and Comments

Transparent BackgroundReturn to overview

Hello, I'm working on a project and I want to make a totally transparent background for my realtime graph.

https://imgur.com/a/fx4Jejq This is my current graph and i want to see clearly the map behind.
Do you know if it's possible to do that ?

This is my code to modify the aspect of the graph

    customPlot->addGraph();
    customPlot->graph(0)->setPen(QPen(QColor(255, 0, 0)));

    //customPlot->setAttribute(Qt::WA_OpaquePaintEvent, false);
    //customPlot->setBackground(Qt::GlobalColor::transparent);

    // Mise en place d'un couleur pour tracer les axes
    QPen axis_pen;
    axis_pen.setColor(QColor(255,0,0));

    QSharedPointer<QCPAxisTickerTime> timeTicker(new QCPAxisTickerTime);
    timeTicker->setTimeFormat("%h:%m:%s");
    customPlot->xAxis->setTicker(timeTicker);
    customPlot->xAxis->setBasePen(axis_pen);    //On change la couleur de l'axe
    customPlot->xAxis->setTickLabelColor(QColor(255,0,0));  //On change la couleur des données
    customPlot->xAxis->grid()->setPen(axis_pen);    //On change la couleur de l'axe
    customPlot->xAxis->grid()->setZeroLinePen(axis_pen);
    //customPlot->xAxis->setLabel("T I M E");

    customPlot->axisRect()->setupFullAxesBox();
    customPlot->yAxis->setLabel("C U R R E N T");
    customPlot->yAxis->setLabelColor(QColor(255,0,0));
    customPlot->yAxis->setRange(-10, 100);
    customPlot->yAxis->setBasePen(axis_pen);
    customPlot->yAxis->grid()->setPen(axis_pen);    //On change la couleur de l'axe
    customPlot->yAxis->grid()->setZeroLinePen(axis_pen);
    customPlot->yAxis->setTickLabelColor(QColor(255,0,0));

    customPlot->setBackground(QBrush(Qt::transparent));
    //customPlot->axisRect()->setBackground(Qt::red);

Thanks !

Hello my fellow french speaking friend,

A Qcustomplot is composed of different elements that are drawn in some order. So what you see are the elements that were drawn on top. By setting the background color of the QCustomplot,
you're setting the color where no element was drawn on top (you can easily see the difference by setting it all black or something like that). What is still visible in your image is the axisRect
so by also changing the background color of the axisrect to transparent it should do the trick.

PS : I see that in your code you do
QPen axis_pen;
axis_pen.setColor(QColor(255,0,0));
you could have used the color constructor of QPen directly instead of using the empty constructor that could maybe do some unwanted stuff in other cases.
QPen axis_pen(QColor(255,0,0));