PDA

View Full Version : plotmatrix canvas size after rescale



bbrondel
24th July 2013, 19:36
Hi all.

I'm playing with Qwt and having some trouble with the plotmatrix example. In the example, I added a line in the MainWindow constructor after the calls to setAxisScale, as follows:



setAxisScale(QwtPlot::yLeft, 2, -2, 2);


which calls setScaleAxis on the leftmost plot in the bottom row with limits -2 and 2. When I run the program, the scale comes out right, but the bottom row of plots is taller than the other rows. A screenshot is attached. What I want is for all the plots in the matrix to have the same size. How can I acheive that?

Thanks.

Uwe
25th July 2013, 06:13
The size hints of a plot widget depend on its tick labels - guess this is the reason, why the grid layout acts this way. Try to change the size policies of the plot, if this doesn't work you have to derive from QwtPlot and overload minimumSizeHint()/sizeHint().

See QWidget::setSizePolicy(), QWidget::sizeHint(), QWidget::minimumSizeHint().

Uwe

bbrondel
31st July 2013, 16:30
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


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();
}


I'm not sure this is quite right, but the plots look good.

Thanks again.