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:

if you want to make it appear again, just calll


Hi Emanuel,

Your solution works very well.

thank you

Hi all,

I just found this topic. I try to hide some graphs. The solution proposed by DerManu works perfectly fine. However, the graph is added at the end of the legend. Is it possible to add the entry in the legend at the same row it was before without clearing completely the legend and filling it again?



if someone still have this issue, the easy work around is to call removeFromLegend for all your graphs, and then add them again in the correct order.