PDA

View Full Version : Showing small axis legend in QwtPlot



ahisham
24th February 2014, 14:30
Hi all,

I would like to show a small arrows pointing to +ve x and y directions inside the Qwt plotting area. I am already using Qwt axis with scales on them without any problem. Just for usability, it will be very useful to have a 90-degree small arrows corresponding to +ve x and y directions. This would be static at a corner of the plotting area and shouldn't pan or zoom with the plot.

What would be the appropriate way for drawing this ?

Thanks

Cah
25th February 2014, 02:00
subclass QwtPlotItem and re-define draw()

Something like this ...




class RefArrow: public QwtPlotItem
{
public:
explicit RefArrow(){}
virtual ~RefArrow(){}

void draw( QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect ) const
{
QLineF vline(20, canvasRect.height()-20, 20, canvasRect.height()-80);
QLineF hline(20, canvasRect.height()-20, 100, canvasRect.height()-20);
painter->save();
QPen p(Qt::red, 3);
painter->setPen(p);
painter->drawLine(vline);
painter->drawLine(hline);
painter->restore();
}
};

Then ...



....

RefArrow * refArrow = new RefArrow;
refArrow->attach(plot);
...


This should give lines at 90 degrees and parallel to the axes.
It should be easy to add arrows

The stockchart example shows how one can implement there own PlotItems

ahisham
25th February 2014, 19:48
Perfect .. Exactly what I am looking for :)

Thanks