QCustomPlot Discussion and Comments

Setting transparent background does leaves previous drawings in placeReturn to overview

Goal:
The background of the QCustomPlot widget should be the same color as the MainWindow color and I prefer this is "inherited" rather than defined on the widget itself.
*All* transparent backgrounds work fine in other widgets (QLabel, QPushButton, etc).

Method

With QCustomPlot, the background is white by default. So I set it to transparent:

    ui->graphicsView->setBackground(Qt::GlobalColor::transparent);

However, when the widget is drawn, any drawing that was previously in the location of the QCustomPlot widget is left in place (I get old text, old buttons, old images of widgets that no longer exist).

The issue is the of the same kind as explained in the qtcenter thread where the following answer appears: https://www.qtcentre.org/threads/3310-clean-with-transparent-color#post_52434 .

I bluntly tried

ui->graphicsView->paintEngine()
    ->painter()->setCompositionMode(QPainter::CompositionMode_Clear);

but that resulted in a segmentation fault.

What method should I use to make sure that the background is redrawn for the QCustomPlot?

Try

ui->graphicsView->setBackground(Qt::GlobalColor::transparent);
ui->graphicsView->setAttribute(Qt::WA_OpaquePaintEvent, false);

assuming your QCustomPlot is ui->graphicsView.

(see https://www.qcustomplot.com/index.php/support/forum/549)