QCustomPlot Discussion and Comments

Change background color of qcustomplot from white to yellow and backReturn to overview

I promoted a QWidget to QCustomPlot. The background is normally white. I want to change it to yellow when data stops coming into the plot.

In QtCreator I can force the color change using the stylesheet change selection when I right click on the plot.

That color doesn't remain when I compile and run. When running the plot shows up with a white background.

I've tried the stylesheet change methods suggested in this forum and the palette methods in code under a pushbutton slot, these do not change the background color either. Has anyone successfully done this? If so please answer with a code snippet.

Thanks to all


QCustomPlot has is own layout so you can't use the setStyleSheet...

Here's the code snippet we used to change the graph color to black & white(light grey) :

void AbstractCustomPlot::setTheme(bool isLite)
    QColor accentColor;
    QColor themeColor;
    QColor themeBackgroundColor;
    QColor traceColor;
    if (!isLite) {
        accentColor = QColor(78, 156, 207);
        traceColor = accentColor;
        themeColor = QColor(Qt::gray);
        themeBackgroundColor = QColor(48,47,47);
        accentColor = QColor(Qt::darkBlue);
        traceColor = accentColor;
        themeColor = QColor(Qt::black);
        themeBackgroundColor = QColor(Qt::white);

    foreach(QCPAxisRect* rect, axisRects()){
        foreach(QCPAxis* axis, rect->axes()){
            axis->setBasePen(QPen(themeColor, 1));
            axis->setTickPen(QPen(themeColor, 1));
            axis->setSubTickPen(QPen(themeColor, 1));
            axis->grid()->setPen(QPen(themeColor, 0.5, Qt::DotLine));

            axis->setSelectedBasePen(QPen(accentColor, 1));
            axis->setSelectedSubTickPen(QPen(accentColor, 1));
            axis->setSelectedTickPen(QPen(accentColor, 1));

Hope it will help !

I couldn't get this to compile even with lots of manipulations to fit my environment.

My compiler barfs on QCPAxisRect, QCPAxis and replotNow(). My customPlot widget has a replot() method associated with it but no replotNow();

I wish I could post a screenshot of what I need to accomplish. It might be easier to implement. I could email someone the screenshots.

My goal is to leave the black color of the x and y axis as they are, leave my plotted data lines the color they are. what I need changed is the white background they all set on top of.

If you want to set the background of the entire QCustomPlot widget, have a look at the documentation of QCustomPlot::setBackground.
If only the axis rect shall change background color, check out QCPAxisRect::setBackground.

That should already solve your requirement.