View Full Version : multiple plots in QVBoxLayout: different length of legends, but same canvas width?

14th October 2008, 12:34
hi everyone,

i finally got my "multiple-plot-widget" to work, using a QVBoxLayout which contains serveral plots.

down at the bottom, below all the plots, is a scale which should apply to all plots. therefore, all the plots (i think it's what you call their canvas) have to have the same width - independent from the length of each one's legend text.

here's a screenshot of what it looks like now:

as you can see, the painting area's width depends on the legend text's length.

i tried filling all the legend texts with less characters with spaces, so they're the same length as the longest one, but that doesn't work well, because all the characters have individual widths themselves.

so my question is, how can i make sure the width of the canvas/painting area is always the same width (in all plots), no matter how long the legend text is?

thanks in advance and sorry for my poor english!

15th October 2008, 09:54
I'm not sure if I'm right, but you should set the geometry the plots to a fixed size using the setGeometry() method.

15th October 2008, 10:40
thanks, i will try that.

but if it really sets the geometry of the whole plot widget, it won't work i guess, because the legend on the right (symbol/text) is actually part of the plot widget.
that's why i probably need to set a fixed size for the "canvas"/"painting area"/"left part"/hope you know what i mean ... ;)

but i will try setGeometry first before i complain too much. :)

// EDIT: as i expected, setGeometry unfortunately doesn't work, because the width/height of all the plots is the same.
anyway, thanks for the answer, at least one person who read all the stuff! :)

// EDIT2: btw: setting the minimum- and maximum-width for the legend item (legend()) and/or canvas (canvas()) doesn't work aswell.
the legend/canvas is resized, but the "actual painting area" (like when you resize the whole plot widget, the whole painting are + scale is scaled correctly) isn't resized.


15th October 2008, 11:58
Insert the legend as QwtPlot::ExternalLegend and organize your plots and legends in a QGridLayout.
Note, that external legends are not printed by QwtPlot::print. So if you need printing you have to call QwtPlot::printLegend() manually.


15th October 2008, 13:24
thanks alot uwe!
i read that part of the docs so many times but just didn't see its importance ...
everything works fine now!