QCustomPlot Discussion and Comments

Setting QFrame as CustomPlotZoom's parent disables the plot's zooming ability and mouse eventsReturn to overview

Hi, everyone. I create a plot with CustomPlotZoom like this:

//inside MainWindow's constructor
QWidget *widgetMain = new QWidget(this);
setCentralWidget(widgetMain);
auto *gridMain = new QGridLayout(widgetMain);

plot = new CustomPlotZoom(this);
gridMain->addWidget(plot);

In this plot, when I click on various parts of the graph, I can see the (x,y) coordinates. Also, I can zoom in on the plot.
Now I want to add a border to my plot. I found no other way than encapsulating the plot inside a QFrame object like this:

QFrame *frame = new QFrame();
frame->setFrameShape(QFrame::StyledPanel);

plot = new CustomPlotZoom(frame);
QVBoxLayout *frameLayout = new QVBoxLayout(frame);
frameLayout->addWidget(plot);
gridMain->addWidget(frame,2,0,2,10);

With this code, a border appears around my plot (even though the plot becomes a little smaller). However, I've noticed that the plot cannot be zoomed in anymore, and the coordinates are also not shown when I click on the graph. So I have two questions:
1) Why does this happen and how can I fix it (still using QFrame)?
2) Is there any way to add a border to the plot or simply change the color of the edges other than using QFrame?

Thank you.

What I do is to create a QFrame and inside the QFrame create a QWidget, which I promote to QCustomPlot.

Could you please provide more details or a minimal code snippet? Thanks

I use QtCreator's form designer to do this as indicated in this page:

https://www.qcustomplot.com/index.php/tutorials/settingup

Here I drop a QFrame on my form and a QWidget on the frame. Then promote the QWidget to a QCustomPlot. And finally adjust the size of the frame and the widget in the reziseEvent of the application (and remember to subtract frameWidth() twice from the plot width).

I don't really know how to does this in code as it seems that you cannot programmatically "promote" an object. But I guess you could try something along the lines of:

QFrame *plotFrame = new QFrame(this);
QWidget *plotWidget = new QWidget(plotFrame);
QCustomPlot *plot = new QCustomPlot(plotWidget);