QCustomPlot Discussion and Comments

Hello,

i add a title to my plot graph. For example like the code below

plot->plotLayout()->addElement(0,0, new QCPPlotTitle(plot,"TITEL"));

If i update my plot data i want to change my title. How can i do this?

QCPPlotTitle *title = new QCPPlotTitle(plot,"TITEL");
plot->plotLayout()->addElement(0,0, title);
// now you can access it at any time with title->setText, for example

If you need permanent access you can either save the title pointer in a parent class, e.g. MainWindow, but watch out that you don't delete the title in the plot without clearing that external pointer, or you might accidentally access it and create a segfault. or you can access it through the layout system, which will require you to use qobject_cast, though. (see QCPLayoutGrid documentation. The plotLayout() is a QCPLayoutGrid, and you can access elements via the element() method).

Where the QCPPlotTitle had gone? It seems to be non-existent, according to the docs. What if I need to add a title to my customPlot object?

Does this mean I need to go for QCPTextItem? After all, a title is a text item appropriately placed.

QCPPlotTitle was basically renamed to QCPTextElement, see changelog for 2.0.0.
Here's the doc: https://www.qcustomplot.com/documentation/classQCPTextElement.html#details

Everything is in the examples...

ui->customPlot->plotLayout()->insertRow(0);
QCPTextElement *title = new QCPTextElement(ui->customPlot, "Interaction Example", QFont("sans", 17, QFont::Bold));
ui->customPlot->plotLayout()->addElement(0, 0, title);