QCustomPlot Discussion and Comments

Question about buffered layers (they are not redrawn after the item is added?)Return to overview

Hello!

Please see this code:

#include <QApplication>
#include "qcustomplot.h"

class MyPlot : public QCustomPlot{
    QPointer<QCPItemText> textItem;

public:
    MyPlot() : QCustomPlot()
    {
        setInteraction(QCP::iRangeZoom, true);
    }

    void enterEvent(QEvent *event) Q_DECL_OVERRIDE
    {
        QCustomPlot::enterEvent(event);

        if(!textItem){
            textItem = new QCPItemText(this);
            textItem->setText("Hello");
            textItem->setLayer("overlay");
            textItem->position->setType(QCPItemPosition::ptAbsolute);
            textItem->position->setCoords(width()/2, height()/2);
            layer("overlay")->replot();
            //replot(); //works if this function is called
        }
    }

    void leaveEvent(QEvent *event) Q_DECL_OVERRIDE
    {
        QCustomPlot::enterEvent(event);

        removeItem(textItem);
        layer("overlay")->replot();
        //replot(); //works if this function is called
    }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    MyPlot w;
    w.show();

    return a.exec();
}

Citation from the documentation:
"By default, only the topmost layer called "overlay" is in mode lmBuffered"

When I add the item to the buffered layer (not only in default, but also in others created by me),
and call layer(NAME)->replot(); , the Plot does not redraw the picture on the screen.

Yes, i can call QCustomPlot::replot(), but in this case all layers will be redrawn.
In some of them can contain graphics with tens of thousands of points, with a line thickness of more than 1 pixel.
Redrawing all layers will cause a large delay. (Yes, I can enable openGl, but for a number of reasons I do not do it)

Question: Am I doing something wrong? or is it a restriction from QCP?

Hi, could you send the entire demo project that shows this behaviour to the support email address? I'll have a look at it.

Sent *.7z archive, but google-mail ate the file extension.