PDA

View Full Version : qwt-6.0.2 subclassing QwtPlotCurve and reimpl. drawSymbols for rotated markers



corrado1972
13th May 2013, 15:17
Hello you all,
I'm using qwt 6.0.2 and I'm trying to draw rotated markers by a custom angle, tipically 30° counterclockwise.

Surfing the group, I found this (http://www.qtcentre.org/threads/12495-rotating-a-custom-made-symbol-for-QwtPlotCurve) thread in which is described how to plot custom markers/symbols: unfortunately doesn't work for me, because the signature of the method QwtPlotCurve::drawSymbols doesn't match with my version.
How do I solve this?

Added after 57 minutes:

Actually I solved quick and dirty modifying directly QwtPlotMarker sources.

Addedo to .h:


void setLabelRotationAngle(double angle = 0.0);
...
private:
double _rotationAngle;


Added to .cpp:


QwtPlotMarker::QwtPlotMarker():
QwtPlotItem( QwtText( "Marker" ) ),
_rotationAngle(0.0)
{
d_data = new PrivateData;
setZ( 30.0 );
}
.....
void QwtPlotMarker::setLabelRotationAngle(double angle)
{
_rotationAngle = angle;
}

and into drawlabel method:


void QwtPlotMarker::drawLabel( QPainter *painter,
const QRectF &canvasRect, const QPointF &pos ) const
{
.....
if (_rotationAngle != 0.0){
painter->setRenderHint(QPainter::Antialiasing);
painter->rotate(_rotationAngle);
}
const QRectF textRect( 0, 0, textSize.width(), textSize.height() );
d_data->label.draw( painter, textRect );
}

the client side:


marker->setLabel(QString::fromLatin1(QDateTime::fromTime_t (ge->timestamp).toString("hh:mm").toAscii()));
marker->setLabelOrientation(Qt::Horizontal);
marker->setLinePen(QPen(Qt::darkGray, 0, Qt::DotLine));
marker->setLineStyle(QwtPlotMarker::NoLine);
marker->setXValue(ge->timestamp);
marker->setYValue(d);
marker->setLabelAlignment(Qt::AlignCenter | Qt::AlignLeft);
// the tip:
marker->setLabelRotationAngle(-30.0);

curve->add_marker(marker);
marker->attach(this);

the results: