Thank you for your answer.
I made a solution just a bit more generic, which works well:
{
public:
const double pos = 0.0 ):
{
}
protected:
void updateScaleDiv( const QwtScaleDiv& xScaleDiv,
const QwtScaleDiv& yScaleDiv )
{
switch(m_alignment)
{
m_scaleDiv.setInterval(xScaleDiv.interval());
break;
m_scaleDiv.setInterval(yScaleDiv.interval());
break;
}
}
private:
};
class ScaleItem: public QwtPlotScaleItem
{
public:
ScaleItem(const QwtScaleDiv& scaleDiv, QwtScaleDraw::Alignment alignment = QwtScaleDraw::BottomScale,
const double pos = 0.0 ):
QwtPlotScaleItem( alignment, pos), m_scaleDiv(scaleDiv), m_alignment(alignment)
{
}
protected:
void updateScaleDiv( const QwtScaleDiv& xScaleDiv,
const QwtScaleDiv& yScaleDiv )
{
switch(m_alignment)
{
case QwtScaleDraw::BottomScale:
case QwtScaleDraw::TopScale:
m_scaleDiv.setInterval(xScaleDiv.interval());
QwtPlotScaleItem::updateScaleDiv( m_scaleDiv, yScaleDiv );
break;
case QwtScaleDraw::LeftScale:
case QwtScaleDraw::RightScale:
m_scaleDiv.setInterval(yScaleDiv.interval());
QwtPlotScaleItem::updateScaleDiv( xScaleDiv, m_scaleDiv);
break;
}
}
private:
QwtScaleDiv m_scaleDiv;
const QwtScaleDraw::Alignment m_alignment;
};
To copy to clipboard, switch view to plain text mode
It gives the following expected result after zooming:
afterzoom.jpg
I know have a question about the labels of these scale. As you can see in the screenshot above, they are hardly reading because the overlap with the colored square. I am using QwtPlotScaleItem::scaleDraw()->setLabelAlignment(Qt::AlignBottom | Qt::AlignLeft); which improves the situation.
However i need to shift a bit the labels (on the left for the horizontal scale, and to the bottom for the vertical scale). I tried the QwtPlotScaleItem::scaleDraw()->setSpacing(40) but it does not shift in the direction I need. Do i need to subclass QwtScaleDraw for this ?
Again, many thanks !
Eric
Bookmarks