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 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;
void setLabelRotationAngle(double angle = 0.0);
...
private:
double _rotationAngle;
To copy to clipboard, switch view to plain text mode
Added to .cpp:
_rotationAngle(0.0)
{
d_data = new PrivateData;
setZ( 30.0 );
}
.....
{
_rotationAngle = angle;
}
QwtPlotMarker::QwtPlotMarker():
QwtPlotItem( QwtText( "Marker" ) ),
_rotationAngle(0.0)
{
d_data = new PrivateData;
setZ( 30.0 );
}
.....
void QwtPlotMarker::setLabelRotationAngle(double angle)
{
_rotationAngle = angle;
}
To copy to clipboard, switch view to plain text mode
and into drawlabel method:
{
.....
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 );
}
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 );
}
To copy to clipboard, switch view to plain text mode
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->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);
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);
To copy to clipboard, switch view to plain text mode
the results:
Bookmarks