I tried this which helps a little bit. However, the canvas doesn't move now but the scales will jump in size when there are long tick labels.
After looking into it more, I think that I found the issue but I am unable to figure out how to figure it.
Findings and Example Scenario:
I have a plot which has a xBottom scale of 0 to 10000. When using even normal sized font of 10pt, the right side tick label of "10,000" uses about 50-60 pixels to display. When that label is centered under the tick mark, the right portion uses 25-30 pixels of space. Now when the QwtScaleWidget::getBorderDistHint() function gets called, it calls the QwtScaleDraw::getBorderDistHint() function and it returns the "end" parameter to be 25-30 pixels to accomodate the "10,000" tick label.
0to10000plot..png
Figure 1: 0 to 10000 Plot
Now because of the long tick label and the fact that the canvas and scale widget are not aligned (see QwtPlotLayout::setAlignCanvasToScale() function), the scale goes from 0 to 10000 while the canvas displays values from about -10 to 10700. The difference is because the tick label causes the tick mark to adjust so that the label can be displayed.
So where the "jumpy" looks comes in happens when you change the scale of the xBottom scale to be -1 to 9999. When this happens, the "10,000" tick label doesn't need to show anymore and the QwtScaleDraw::getBorderDistHint() function returns 0 for the "end" parameter. Effectively, the scale widget goes from -1 to 9999 and the canvas aligns naturally and goes from -1 to 9999. Thus, the sudden change in scale ranges for the canvas and scale widget cause it look jumpy when panning.
-1to9999plot..png
Figure 2: -1 to 9999 Plot
Solutions:
- I would think that sub-classing from the QwtScaleDraw class to overload the getBorderDistHint() function would be the way to handle this by always passing back a 0 for the "end" parameter. However, this function is not virtual for some reason.
- Sub-class from the QwtScaleWidget class to hold a custom QwtScaleDraw class and work around the issue that way. I see that the QwtScaleWidget class has virtual members which makes me think that I can sub-class from it. However, I don't see a way to create or set the scale widgets in the QwtPlot class.
- ??? - Now I am stuck???
Any help or ideas on how to work around this?
Youal ready got the answer im my previous mail.
Uwe
The only thing that the previous mail answered is that to use minimumExtent. I don't understand how to make that work.
The difference is that I don't know if the tick label is going to be 5 pixels long or 50 pixels long and I don't want to set the minimumExtent to be 50 pixels all of the time. It seems like having the ability to make one of the methods above have a virtual function is the way to go.
Since you, Uwe, designed and wrote it, why didn't you make some of the functions virtual like the QwtScaleDraw::getBorderDistHint() function?
Last edited by amoswood; 10th June 2010 at 14:16. Reason: spelling corrections
Amos
Qt Programmer Extraordinaire
Current Work:
Ripxx Sports Measurement Device - www.ripxx.com
(Featured in MYTHBUSTERS on 2010-05-19 in S08E08)
Bookmarks