QCustomPlot Discussion and Comments

Legend size and curves visibilityReturn to overview

Hello everyone,

When I hide a curve via the code :

myQCPGraph-> setVisible (false);

I also hide the associated item in the legend of the QCP via the code:

myQCP-> legend-> itemWithPlottable (myQCPGraph) -> setVisible (false);

Thanks to these two instructions, I have my curve that hides, just like its associated element in the legend of the QCP.

However, I note that the size of the legend does not change. Is there a way to automatically resize the legend size? Indeed, when I hide an element, the legend contains an empty white space. So I'm looking for a way to reduce its size.

My research in the documentation and on the forum were unsuccessful.

Thanks for your help.

Rather than hiding, you should remove the according legend item:
myQCPGraph->removeFromLegend();

if you want to make it appear again, just calll

myQCPGraph->addToLegend();

Hi Emanuel,

Your solution works very well.

thank you