PDA

View Full Version : access plot rectangle before QwtScaleDraw::label is called?



kja
14th July 2011, 07:14
Hi,
I've been searching for this all day, perhaps someone can point me in the right direction.

What function do I need to overload to find the current rectangle of my canvas before
QwtScaleDraw::label(double value) is called?

I know the first time QwtScaleDraw::label(double value) is called 'value' is the minimum value of the axis, and the second time it is called 'value' is the max value of the axis. I want to be able to know the min and the max value before QwtScaleDraw::label is called (everytime it is called)

The reason I want to know this is to make the dates on my x axis change depending on how big of a time frame is displayed on the plot. For example, if it is a 10 year span, I only want years as labels, but if it is 10 minutes I'd like minutes.

I've been trying to do this a hacky way by getting the zoom rect's but nothing I have tried works in all cases, for example, if the user zooms out to a bigger area.

I've also tried overloading QwtScaleWidget::layoutScale because it seems to have a rect() function. But my code never seems to get to it:


class ScaleWidget : public QwtScaleWidget{
public:
ScaleWidget(){}
void layoutScale(bool update_geometry){
const QRectF r = rect(); // I think I want this rect!
QwtScaleWidget::layoutScale();
}
};


Please, any ideas?
Thanks a lot!

kja
15th July 2011, 03:32
Ah ha! I think I finally found what I need. I just call this within QwtScaleDraw::label



QwtScaleMap map = this->map();
double xBegin = map.s1();
double xEnd = map.s2();

This give me the min and max values of my xBottom axis!

Uwe
15th July 2011, 07:25
Or do the following:


double xBegin = scaleDiv().lowerBound();
double xEnd = scaleDiv().upperBound();
Uwe