PDA

View Full Version : A way to align different QwtPlot objects?



agarny
28th May 2015, 18:06
I have several QwtPlot objects, which are used to plot something against time. Now, the scale of that something can vary, meaning that the labels used to render the Y axis can be different from one QwtPlot object to another, and this results in the length of the X axis of my QwtPlot objects being different too. An example of what I am talking about can be seen here (https://cloud.githubusercontent.com/assets/602265/7787729/1240278a-0213-11e5-97a8-37f2e6eb76d1.png) (ignore the red "OV"; the screenshot was annotated by a colleague of mine).

That difference in length of the X axis of my different QwtPlot objects is clearly not neat. I was therefore wondering whether there would be a way to ensure that they are all of the same length?

Cheers, Alan.

Uwe
29th May 2015, 07:07
This has been asked and answered many times - check the forum and/or have a look at the plotmatrix example.

Uwe

agarny
29th May 2015, 07:34
I did check, but clearly not using the right keywords. Anyway, thanks for the tip, I am going to check the plotmatrix example.

Alekon
30th June 2015, 10:05
plotmatrix gives a useful.

But further problem is Y-axis (left or right) title. For long string with several words it can occupy >=1 lines, so the plots might be unaligned again. E.g. first plot has 1 line Y-axis title and second plot has 2 lines Y-axis.

How is it possible to disable wrapping of axis titles? Or, may be other way?

Thanks.

Added after 37 minutes:

Obviously, title font (size, family, etc.) also affects on title width. How is it possible to specify title width for QwtScaleWidget internal layout?

I think it will be amazing if a QwtPlot will have a feature for such alignment with other plot:

QList<QwtPlot*> layoutSyncingPlots(); // all syncing plots
void QwtPlot::addLayoutSyncingPlot(const QwtPlot& other);

In that 'layout syncing' group each plot tracks other plots and best syncing layout is found and applied for all plots in the group after any scale or size change. Of course, that syncing maybe better to implements through a dedicated separate class.

Alekon
6th July 2015, 10:09
11254
In the attach there are two plots with left-aligned X-axises (using "plotmatrix" example's way). How to align right axises? Note, that the plots differ by legend sizes and using/not using right Y-axis.

Uwe
7th July 2015, 06:47
You could try to align the legend by manipulating the sizeHints of the legend items ( maybe by overloading QwtLegend::createWidget() ). Another option is not to insert the legends into the plot layout ( QwtPlot::insertLegend() ) and to put it into a QGridLayout instead.

Uwe

Alekon
7th July 2015, 12:09
Thanks a lot. Solved the problem by suitable for my requirements way. Legend was aligned with sizeHint() overriding; scales were aligned with adding fake invisible right Y-axis to the plot that has no right Y-axis. Now, it looks like this (attach). If someone interest the solution I can share the details.
11257

Alekon
8th July 2015, 08:10
I have encountered a problem. Under some size the legend does not placed in right side, there is a gap appears (see attach). The plot is brushed as follows:
qwtpltMain_->setAutoFillBackground(true);
qwtpltMain_->setBackgroundRole(QPalette::Dark);
11258

Alekon
8th July 2015, 10:55
Hello Uwe,

I'm using Qwt 6.1.0. Please look QwtPlotLayout::layoutLegend() (line 775) and QwtPlotLayout::LayoutData::init() (line 85) routings. It seems that there is twice compensation of legend width (vertical legends are considered) by value "legend.hScrollExtent". Is it right?

Thanks

... as an option to explore the problem quickly I patched QwtLegend::scrollExtent() to permanently return 0 regardless of a scrollbar need, so twice compensation becomes "masked". It works as I expected - no extra width increasing. So, there is the twice compensation bug.

Alekon
8th July 2015, 14:17
I have another issue (see attach). X-axis label (8000) on bottom plot shifts the plot canvas, so there is extra space between canves and legend. How can I "trim" scale widget to be under plot canvas without extents?

Thanks.
11260

Uwe
9th July 2015, 07:39
It seems that there is twice compensation of legend width (vertical legends are considered) by value "legend.hScrollExtent". Is it right?
Yes, I have added a bug report: https://sourceforge.net/p/qwt/bugs/241/

Uwe

Added after 4 minutes:


I have another issue (see attach). X-axis label (8000) on bottom plot shifts the plot canvas, so there is extra space between canves and legend. How can I "trim" scale widget to be under plot canvas without extents?
The default setting is like this - your code seems to change it by setting QwtPlotLayout::setAlignCanvasToScale().

Uwe