{
public:
const QRectF &canvasRect
) const {
QwtPlotSpectrgram::draw( painter, xMap, yMap, canvasRect );
drawGrid( painter, xMap, yMap, canvasRect() );
}
private:
const QRectF &canvasRect
) const {
painter->setPen( ... );
const QRectF hint
= data
()->pixelHint
();
// vertical lines
const double x1 = xMap.invTransform( canvasRect.left() );
const double x2 = xMap.invTransform( canvasRect.right() ),
// aligning x to the beginning of a pixel
const double x = hint.right() + ( qFloor( ( x1 - hint.right() ) / hint.width() ) + 1 ) * hint.width();
for ( ; x < x2, x += hint.width() )
{
const double pos = xMap.transform( x );
painter->drawLine( pos, canvasRect.top(), pos, canvasRect.bottom() );
}
// horizontal lines
...
}
};
class YourSpectrogram: public QwtPlotSpectrogram
{
public:
virtual void draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect ) const
{
QwtPlotSpectrgram::draw( painter, xMap, yMap, canvasRect );
drawGrid( painter, xMap, yMap, canvasRect() );
}
private:
void drawGrid( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect ) const
{
painter->setPen( ... );
const QRectF hint = data()->pixelHint();
// vertical lines
const double x1 = xMap.invTransform( canvasRect.left() );
const double x2 = xMap.invTransform( canvasRect.right() ),
// aligning x to the beginning of a pixel
const double x = hint.right() + ( qFloor( ( x1 - hint.right() ) / hint.width() ) + 1 ) * hint.width();
for ( ; x < x2, x += hint.width() )
{
const double pos = xMap.transform( x );
painter->drawLine( pos, canvasRect.top(), pos, canvasRect.bottom() );
}
// horizontal lines
...
}
};
To copy to clipboard, switch view to plain text mode
HTH Uwe
Bookmarks