PDA

View Full Version : custom axis (setAxisScaleDraw) questions



MrGarbage
2nd January 2008, 21:09
Hi,

From the attached image you see that I have 2 seperate QWtPlots.

I am implementing a custom Y axis scale via:


Status_Graph->setMargin(1);
Status_Graph->enableAxis (QwtPlot::yLeft, true);
m_SimStatusYScaler = new SimStatusYScaleDraw();
Status_Graph->setAxisScaleDraw(QwtPlot::yLeft, m_SimStatusYScaler);
Status_Graph->setAxisScale(QwtPlot::yLeft, 0, 40);
Status_Graph->setAxisLabelAlignment(QwtPlot::yLeft, Qt::AlignLeft | Qt::AlignVCenter);

There are 2 problems I cannot figure out how to solve.

1. I would like the space between the Y axis label (ie Run) and the left
side of the graph itself to be narrower. How/what controls this space?

2. I would like the 2 graphs to be the same width with their left edges
aligned. They start out that way
in QT Designer but when I add the custom Y scale obviously the upper
graphs narrows.


Thank you!

Mark

Uwe
3rd January 2008, 10:05
I would like the space between the Y axis label (ie Run) and the left side of the graph itself to be narrower.
a) QwtAbstractScaleDraw::setSpacing
b) QwtScaleWidget::setMargin

I would like the 2 graphs to be the same width with their left edges aligned.
You have to use QwtScaleDraw::exent/QwtScaleDraw::setMinimumExtent. See the implementation of alignVAxis here: http://qwt.svn.sourceforge.net/viewvc/qwt/trunk/qwt/examples/plotmatrix/plotmatrix.cpp?revision=135&view=markup

Uwe

MrGarbage
3rd January 2008, 21:48
Thanks - that did the trick - awesome..

I now added a label to the Y-axis and that shifts the graph to
the right. I assumed I needed to subtract out the label portion
but the labelSz.height() value alone isn't sufficient to get the
2 graphs aligned..

What am I missing?



// Get the Y-axis label component to subtract out from the extent
scaleWidget = Simulation_Graph->axisWidget(QwtPlot::yLeft);
QwtScaleDraw *sd = scaleWidget->scaleDraw();
QSize labelSz = sd->labelSize(scaleWidget->font(),
QwtPlot::yLeft);

scaleWidget = Status_Graph->axisWidget(QwtPlot::yLeft);
sd = scaleWidget->scaleDraw();
sd->setMinimumExtent(0);

const int extent = sd->extent(
QPen(Qt::black, scaleWidget->penWidth()),
scaleWidget->font() ) - labelSz.height();
if ( extent > maxExtent )
maxExtent = extent;

scaleWidget = Simulation_Graph->axisWidget(QwtPlot::yLeft);
scaleWidget->scaleDraw()->setMinimumExtent(maxExtent);

Uwe
4th January 2008, 11:58
I now added a label to the Y-axis and that shifts the graph to
the right.
What do you mean by label - the axis title ?
The title of the axis is painted by the QwtScaleWidget, and you find the corresponding layout code in QwtScaleWidget::dimForLength().

HTH,
Uwe

MrGarbage
8th January 2008, 18:01
Hi Uwe,

I can align my 2 graphs left border now.

However in some cases I display a 2nd Y-axis on the lower graph.
When this occurs I want to now shrink the upper graph so that it's
right border now aligns the right border of the lower graph.

The upper graph does not implement a 2nd Yaxis.

I've tried the same sort of logic that I applied on the left border
including enabling a 2nd Y-axis on the upper graph. Regardless of
what I do with the extent the upper graph size does not change.

Any suggestion on how to accomplish this?

At some point I want to synchronize these 2 graphs such that if
I zoom one, the other zooms as well. They share a common X-axis.
Are there any examples out there of code that implements this sort
of thing?


Many thanks

Mark

Uwe
9th January 2008, 08:19
However in some cases I display a 2nd Y-axis on the lower graph.
When this occurs I want to now shrink the upper graph so that it's
right border now aligns the right border of the lower graph.

You need to add an additional spacer to the right of your upper plot. AFAIR it is possible to use a dummy right axis with no title and where all components of the scale draw are hidden ( QwtAbstractScaleDraw::enableComponent(..., false ). Then you can align the right axes like you did it with the left one.

A more clean situation is to use an QHBoxLayout and put the upper plot and a spacer QWidget into it.


At some point I want to synchronize these 2 graphs such that if
I zoom one, the other zooms as well. They share a common X-axis.

QwtPlotZoomer emits zoomed signals. You can also use the scaleDivChanged() signal of the scale widgets, but you need to be careful to avoid ping pong effects.

HTH,
Uwe

MrGarbage
9th January 2008, 20:08
Hi Uwe,

I don't seem to be able to effect the size of the graph from the Right
Y-axis side at all. Setting a minExtent makes no difference. I have tried
with and without components enabled. I also added a spacer to the right
and layed that out Horizontally.

For example with a backbone enabled on the YRight I see the backbone and
the graph width has initially been adjusted so that the backbone appears
to the right.

The realtime example uses the method you suggested to keep the plot from
jumping all over the place when the YLeft axislabels change.

If there were also a YRight axis and labels for that example
would we not have the same problem?

Where/how does qwt adjust the graph size to accomodate the YRight components?

Any suggestions as to how to proceed?

Thanks
Mark

Uwe
11th January 2008, 11:08
Any suggestions as to how to proceed?
Have a look at the plotmatrix example in the Qwt SVN (trunk).
You can build Qwt 5.1 snapshot from it, to see how the plotmatrix example works.

Uwe