Something like this:
{
public:
YourItem():
m_orientation( Qt::Horizontal ),
m_pen( Qt::red ),
m_brush( Qt::blue )
{
setZ( 0.0 );
}
void setInterval( const QwtInterval &interval )
{
m_interval = interval;
}
void setOrientation( Qt::Orientation orientation )
{
m_orientation = orientation;
}
virtual int rtti() const
{
}
const QRectF &canvasRect
) const {
if ( !m_interval.isValid() )
return;
const double off = qMax( m_pen.widthF(), 1.0 );
if ( m_orientation == Qt::Horizontal )
{
rect.setLeft( canvasRect.left() - off );
rect.setRight( canvasRect.right() + off );
rect.setTop( yMap.transform( m_interval.minValue() ) );
rect.setBottom( yMap.transform( m_interval.maxValue() ) );
}
else
{
rect.setLeft( canvasRect.top() - off );
rect.setRight( canvasRect.bottom() + off );
rect.setLeft( xMap.transform( m_interval.minValue() ) );
rect.setRight( xMap.transform( m_interval.maxValue() ) );
}
rect = rect.normalized();
painter->setPen( m_pen );
painter->setBrush( m_brush );
painter->drawRect( rect );
}
private:
Qt::Orientation m_orientation;
QwtInterval m_interval;
};
class YourItem: public QwtPlotItem
{
public:
YourItem():
m_orientation( Qt::Horizontal ),
m_pen( Qt::red ),
m_brush( Qt::blue )
{
setZ( 0.0 );
}
void setInterval( const QwtInterval &interval )
{
m_interval = interval;
}
void setOrientation( Qt::Orientation orientation )
{
m_orientation = orientation;
}
virtual int rtti() const
{
return QwtPlotItem::Rtti_PlotUserItem;
}
virtual void draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect ) const
{
if ( !m_interval.isValid() )
return;
const double off = qMax( m_pen.widthF(), 1.0 );
QRectF rect;
if ( m_orientation == Qt::Horizontal )
{
rect.setLeft( canvasRect.left() - off );
rect.setRight( canvasRect.right() + off );
rect.setTop( yMap.transform( m_interval.minValue() ) );
rect.setBottom( yMap.transform( m_interval.maxValue() ) );
}
else
{
rect.setLeft( canvasRect.top() - off );
rect.setRight( canvasRect.bottom() + off );
rect.setLeft( xMap.transform( m_interval.minValue() ) );
rect.setRight( xMap.transform( m_interval.maxValue() ) );
}
rect = rect.normalized();
painter->setPen( m_pen );
painter->setBrush( m_brush );
painter->drawRect( rect );
}
private:
Qt::Orientation m_orientation;
QwtInterval m_interval;
QPen m_pen;
QBrush m_brush;
};
To copy to clipboard, switch view to plain text mode
Uwe
Bookmarks