QCustomPlot Discussion and Comments

setMargins changing stretchFactor?Return to overview

Hi! I am creating two QCustomPlots inside a vertical QSplitter. The main aim is to make the two plots behave just like two QWidgets seperated by a QSplitter and since QCustomPlot doesn't have a splitter I am forced to use Qt's QSplitter which results in two different QWidgets being promoted to QCustomPlot. Usually, it works fine but when I set the margins by myself using setMargins()function the height ratios of both plots change, ideally both are supposed to have the same height. My Code:

ui.curPlot->axisRect()->setAutoMargins(QCP::msNone); // Plot in the bottom half of vertical QSplitter
ui.vltPlot->axisRect()->setAutoMargins(QCP::msNone); // Plot in the top half of vertical QSplitter

// Inclusion of the either of the below two lines of code changes the height ratio
ui.curPlot->axisRect()->setMargins(QMargins(75, 1, 10, 45)); // Makes curPlot larger in height
ui.vltPlot->axisRect()->setMargins(QMargins(75, 10, 10, 1)); // Makes vltPlot larger in height

if both of the setMargins() lines are included then curPlot has a larger height than vltPlot.
I can fix it to approximately equal height by manually changing the Stretch Factor of my QSplitter like this:

ui.splitter->setStretchFactor(0, 10); // Changing the stretch factor of vltPlot
ui.splitter->setStretchFactor(1, 7); // Changing the stretch factor of curPlot
Does anyone know why is this happening and how can I fix it?

Maybe it's because the changed margin plays a role in the minimumSizeHint that QCustomPlot reports. So try fixing it by using plot->setMinimumSize on QCustomPlot.

Hi! I tried to use the plot->setMinimumSize() but it changed nothing except for changing the minimum size, which for my use I want to keep at 0 or maybe a very small value like 50. Without setting any minimum size explicitly, I tried getting the current minimum size of my plots using plot->minimumSize() it gave me the same answer QSize(0,0) with and without setting the margins explicitly.
When I try to get plot->minimumSizeHint() it doesn't work, gives me an error and says that the function is inaccessible. It is a protected function I know but it is a protected function of QCustomPlot class so it should be accessible by my plots. I am not sure what's happening here, any idea?