1 Attachment(s)
scale in QwtSlider and QwtPlot
I have a QwtSlider with range (for example) [2, 17]
When it is drawn the scale is "unclear":
Attachment 10676
the uppoer and lower value are not explicitly shown.
similar problem is on QwtPlot scale.
Can I change the scale to show the upper and lower value?
best regards
max
Re: scale in QwtSlider and QwtPlot
The boundaries of a scale and the position of all ticks are defined by a QwtScaleDiv object. Tick labels are painted for major ticks.
A scale division can be assigned manually from application code or can be aligned/calculated by a QwtScaleEngine from its boundaries and a step size. A scale engine implements 2 algorithms:
- aligning the boundaries
see QwtScaleEngine::autoScale() - finding the ticks
see QwtScaleEngine::divideScale()
Each type of scale engine offers parameters that have an impact on its algorithm.
In case of a slider calculating the scale div manually ( QwtAbstractScale::setScale( const QwtScaleDiv & ) ) might be an option, but in case of plot axes the application code often doesn't know about the scales - f.e. when your plot offers any type of navigation ( zooming, panning ... ) - and you need to have an algo for calculating boundaries and ticks.
In case of QwtSlider most relevant methods can be found in its base class QwtAbstractScale.
HTH,
Uwe
Re: scale in QwtSlider and QwtPlot
I have inherit a QwtScaleEngine in this way:
Code:
{
public:
int numMajorSteps, int numMinorSteps,
double stepSize = 0.0 ) const;
};
QwtScaleDiv boundScaleEngine
::divideScale( double x1,
double x2,
int numMajorSteps, int numMinorSteps,
double stepSize) const
{
QwtInterval interval = sd.interval();
double upper,lower;
if(x1>x2)
{
upper = x1;
lower = x2;
}
else
{
upper = x2;
lower = x1;
}
ticks
[QwtScaleDiv::MajorTick].
prepend(lower
);
// add the lower bound tick if it is not present ticks
[QwtScaleDiv::MajorTick].
append(upper
);
// add the upper bound tick if it is not present
}
I used the boundScaleEngine class in both QwtSlider and QwtPlot, and it seems to work properly, but I don't know if there is some pitfalls.
what is your opinion?
bets regards
max
Re: scale in QwtSlider and QwtPlot
Quote:
Originally Posted by
mastupristi
I used the boundScaleEngine class in both QwtSlider and QwtPlot, and it seems to work properly, but I don't know if there is some pitfalls.
what is your opinion?
You have to take care of layout issues: the tick labels at the borders might overlap, when being too close to its neighbors.
Uwe