QCustomPlot Discussion and Comments

QCPAxisRect setMinimumSize() and setMaximumSize()Return to overview


I have a problem with settings size of QCPAxisRect.

// iHeight for example 20
 int iHeight = 20;
m_volumeAxisRect = new QCPAxisRect(&m_hCustomPlot);
m_volumeAxisRect->setMaximumSize(QSize(QWIDGETSIZE_MAX, iHeight));
m_volumeAxisRect->setMinimumSize(QSize(QWIDGETSIZE_MAX, iHeight));

I create screen with 3 qcustomplots. Everyone has this QCPAxisRect with same Min and Max size and same 3 binary graphs into.

One of theese qcustomplots has height 1/2 of screen, rest two qcustomplots has height 1/4 of screen.
At qcustomplot with height 1/2 of screen is this QCPAxisRect bigger then two smallest qcustomplot.

What I doing wrong?

Thanks David.

Sounds like a problem with your external QLayout (Qt's layout for QWidgets). Did you specify different ratios in the layout?

Further, setting the height minimum and maximum to 20 pixels doesn't sound right. If you want them all the same size you should leave the min/max size as they are by default.

This behavior is strange, but i found some workaround.

// (work at embedded screen resolution is 640x480)
// count Height from space given at screen
int iHeight = QtL_W006_BinaryGraphHeight*m_iBinaryValues + QtL_W006_BinaryGraphStrech*m_iBinaryValues + QtL_W006_BinaryGraphOneLineAdd*m_iBinaryValues;

m_volumeAxisRect = new QCPAxisRect(&m_hCustomPlot);
m_volumeAxisRect->setMaximumSize(QSize(QWIDGETSIZE_MAX, iHeight));

// without margins give me size what i defines.

Thanks for help!
Regards David

I think I hit the same problem.

My graph has 5 QCPAxisRect aligned vertically. The bottom-most is supposed to be 50px high, so I do

// create top 4 axis rect, then:
mAxisRectFoo = new QCPAxisRect(mPlot);
mPlot->plotLayout()->addElement(4, 0, mAxisRectFoo);
const int rectHeight = 50;
mAxisRectFoo->setMinimumSize(100, rectHeight);
mAxisRectFoo->setMaximumSize(100000, rectHeight);

which creates a margin about 50px high. But the actual mAxisRectFoo isn't visible at all. When I do


then the 50px axis rect is visible, but not the margin. QCP::msNone also works.

My current solution is

const int rectHeight = 50 + mAxisRectFoo->calculateAutoMargin(QCP::msBottom);

calculateAutoMargin() is a protected method, so I had to change QCPs header, which can't be the answer.

Is this a bug? How can I make the bottommost axis rect have a bottom margin AND the right height?


I just realized there's an error in the documentation: minimum/maximum sizes of layout elements are constraints for the outer rect, not the inner rect (as it's currently stated). Sorry for that.

So when you set the maximum/minimum height to 50, the grid layout will force that cell to a height of 50. The cell corresponds to the outer rect of the layout element, so inner rect including margin.

I will see if there is a nice way to allow specifying whether the max/min sizes are with respect to the inner or outer rect, since (as in your case) some people might really want to constrain the pixel size of the inner rect and let the outer rect grow and shrink depending on the labels.

thanks for the update, I appreciate you looking into this!

To me, a public QCPAxisRect::calculateAutoMargin() doesn't seem like a bad idea, but I'm sure you have your own opinion on this :)

Hi Manuel,

are you still working on QCustomPlot? And on this issue?


Hi Ben,

Absolutely! :)