QCustomPlot Discussion and Comments

Hiding QCPLayerables and grid recalculationReturn to overview

Hello. Let's look at such situation: I have one QCustomPlot widget with multiple QCPAxisRect-s in QCPLayerGrid in one column. I'd like to hide some AxisRect. If I just call "someAxisRect->setVisible(false)" it will disappear, but plot will have white space instead of it. I don't know any method to collapse this space. I tried to do this:
//in hide method
someAxisRect->setVisible(false);
someAxisRect->layout()->take(someAxisRect);
ui->plot->plotLayout()->simplify();

//in show method
plot->plotLayout()->insertRow(row);
plot->plotLayout()->addElement(row,0,someAxisRect);
someAxisRect->setVisible(true);

It works, but I'm not sure it's a proper way, because if I don't change visibility taken AxisRect is still painted under another AxisRect and responds to interactions (selection, e.g.). Any help appreciated.

Hi,

The way you do it is the correct way. The reason the axis rect is still visible in the background if you just remove it from the layout is that layouts control positioning/sizing. So upon removal, the axis rect just keeps its last position and size but gets drawn nevertheless (it hasn't been removed from the plot or set invisible so that's why it's still hanging around there).

This is somewhat unintuitive behaviour, I agree. I'm thinking about making layout elements that don't have a parent layout invisible automatically, so maybe this will change in a future QCustomPlot release.

Many thanks for your help.

Hi
I'm just wondering if there is a new way of doing this with QCustomPlot2.0. Did you change the layout elements or is Phyzic code still the correct way?
Cheers!

Hi,
Have any update for this?

Hi,
Have any update for this?

Layout elements which have no parent (are not in a layout) are still painted if not set to be invisible. It was chosen this way to first of all avoid bugs where people don't get any visual feedback when they still have orphan layout elements (e.g. axis rects) around, and second to allow users controlling layout elements completely manually, using their own layout system on top.

So to remove and re-add an axis rect as the original poster wanted, you can still do it with the calls that he mentioned above. ::take, ::setVisible, and then re-add

Thank you very much. Thank you for your reply

Eso está bien. Ahora sí quisiera mover los gráficos de un axisrect a otro como lo hago