Thanks for the input. I fiddled with the size policies on the plots, but I wasn't able to get anywhere with that. I also derived from QwtPlot and overrode the size hints. That seemed promising, but it was still doing unexpected things. In the end I decided to just lay out the plots by hand in my application. The tricky part was figuring out how much space would be taken up by the axes. In the end I settled on
{
int w = width();
int h = height();
QList<QwtPlot*> plots = findChildren<QwtPlot*>();
int n = plots.size();
// Figure out how much space is used by the axis
sd->setMinimumExtent(0);
int extent = sd->extent(scaleWidget->font());
extent += scaleWidget->spacing();
h -= extent;
// Resize all plots except the bottom
for (int i = 0; i < n-1; ++i) {
plot->setGeometry(0, h / n * i, w, h / n);
plot->replot();
}
// Resize the bottom plot
last->setGeometry(0, h / n * (n-1), w, h / n + extent);
last->replot();
alignLeftAxes();
}
void PlotStack::resizeEvent(QResizeEvent* ev)
{
int w = width();
int h = height();
QList<QwtPlot*> plots = findChildren<QwtPlot*>();
int n = plots.size();
QwtPlot* last = plots.at(n-1);
// Figure out how much space is used by the axis
QwtScaleWidget* scaleWidget = last->axisWidget(QwtPlot::xBottom);
QwtScaleDraw* sd = scaleWidget->scaleDraw();
sd->setMinimumExtent(0);
int extent = sd->extent(scaleWidget->font());
extent += scaleWidget->spacing();
h -= extent;
// Resize all plots except the bottom
for (int i = 0; i < n-1; ++i) {
QwtPlot* plot = plots.at(i);
plot->setGeometry(0, h / n * i, w, h / n);
plot->replot();
}
// Resize the bottom plot
last->setGeometry(0, h / n * (n-1), w, h / n + extent);
last->replot();
alignLeftAxes();
}
To copy to clipboard, switch view to plain text mode
I'm not sure this is quite right, but the plots look good.
Thanks again.
Bookmarks