QCustomPlot Discussion and Comments

Image as background for plot is not workingReturn to overview

Hi,

I've been trying the last two days to set an image as a background for my plot.
My first attempt was the following:
ui->mapPlot ->axisRect() -> setBackground(QPixmap("./sun.png"));

The code builds, but no image is rendered in the background.
I also found code online suggesting that the following might work

    QCPItemPixmap *MyImage = new QCPItemPixmap(ui -> mapPlot);
    MyImage->setPixmap(QPixmap("./sun.png"));
    MyImage->topLeft->setType(QCPItemPosition::ptPlotCoords);
    MyImage->bottomRight->setType(QCPItemPosition::ptPlotCoords);
    MyImage->topLeft->setCoords(ui -> mapPlot ->xAxis->range().lower, ui -> mapPlot->yAxis->range().upper);
    MyImage->bottomRight->setCoords(ui -> mapPlot->xAxis->range().upper, ui -> mapPlot->yAxis->range().lower);
    MyImage->setScaled(true,Qt::IgnoreAspectRatio);
    ui -> mapPlot->setCurrentLayer("background");
    ui -> mapPlot->addItem(MyImage);   

I get the following error message: error: ‘class QCustomPlot’ has no member named ‘addItem’

What might I be doing wrong? Is there a specific header I must include? I'm fairly new at QT and QCustomPlot.
Btw, setting the background as a color works fine.

- Thanks

in *.pro

RESOURCES += \
    sun.png

in *.cpp

axisRect->setBackground(QBrush(QPixmap(":/sun.png"))); // (":", not ".")

run qmake, run rebuild

Wonderful!It works now, thank you !