The documentation of QCPLayoutElement::setMargins() says that the margin is ignored when auto-margin is set for that side. However, the QCPLayoutElement::calculateAutoMargin() does not ignore the mMargins and uses it in auto-margin calculation. This causes problems when interactively changing the plot. Imagine following scenario:

- Add a text element to a layout above the axis rectangle.
- Set the left side of text element and the axis rectangle into a margin group.
- Replot (calculates the layout and the margin of the text element is set to the calculated auto-margin driven by the left axis).
- Hide the left axis. The expected result is that the plot expands over the space previously occupied by the axis.
- Unfortunately the left margin stays as it was before because now the auto-margin is driven by the previously stored margin value in the text element.

I fixed this in my sub-class of the text element by really ignoring the mMargins in calculateAutoMargin(); in my opinion this should be fixed in the QCPLayoutElement::calculateAutoMargin().