Hi, everyone.
I am using qwt-6.1.0 library. I want to draw scales inside the plot canvas. I have read the example which is given in QwtPlotScaleItem class reference and created a subclass of QwtPlot where in constructor I wrote this:
scaleItemY->setBorderDistance(0);
scaleItemY->attach(this);
this
->enableAxis
(QwtPlot::yLeft,
false);
scaleItemX->setBorderDistance(0);
scaleItemX->attach(this);
this
->enableAxis
(QwtPlot::xBottom,
false);
QwtPlotScaleItem *scaleItemY =
new QwtPlotScaleItem(QwtScaleDraw::RightScale);
scaleItemY->setBorderDistance(0);
scaleItemY->attach(this);
this->enableAxis(QwtPlot::yLeft, false);
QwtPlotScaleItem *scaleItemX =
new QwtPlotScaleItem(QwtScaleDraw::TopScale);
scaleItemX->setBorderDistance(0);
scaleItemX->attach(this);
this->enableAxis(QwtPlot::xBottom, false);
To copy to clipboard, switch view to plain text mode
Here everythig is ok. When I attach grid it cross labels, and now I want to shift labels, so that there would be no intersections of grids and labels. For that I have created a subclasses (XScaleDraw and YScaleDraw) of QwtScaleDraw class where i override virtual void drawLabel (QPainter* painter, double value) const function: instead of
lbl.
draw ( painter,
QRect( QPoint( 0,
0 ), labelSize.
toSize() ) );
lbl.draw ( painter, QRect( QPoint( 0, 0 ), labelSize.toSize() ) );
To copy to clipboard, switch view to plain text mode
I wrote (for X shift) :
lbl.
draw ( painter,
QRect( QPoint( 0+(int)(labelSize.
width()/2),
0 ), labelSize.
toSize() ) );
lbl.draw ( painter, QRect( QPoint( 0+(int)(labelSize.width()/2), 0 ), labelSize.toSize() ) );
To copy to clipboard, switch view to plain text mode
and for Y shift:
lbl.
draw ( painter,
QRect( QPoint(0,
0+(int)(labelSize.
height()/2) ), labelSize.
toSize() ) );
lbl.draw ( painter, QRect( QPoint(0, 0+(int)(labelSize.height()/2) ), labelSize.toSize() ) );
To copy to clipboard, switch view to plain text mode
Now I set scale draw and after that problems arise:
scaleItemY->setScaleDraw(new YScaleDraw);
scaleItemY->setBorderDistance(0);
scaleItemY->attach(this);
this
->enableAxis
(QwtPlot::yLeft,
false);
scaleItemX->setScaleDraw(new XScaleDraw);
scaleItemX->setBorderDistance(0);
scaleItemX->attach(this);
this
->enableAxis
(QwtPlot::xBottom,
false);
QwtPlotScaleItem *scaleItemY =
new QwtPlotScaleItem(QwtScaleDraw::RightScale);
scaleItemY->setScaleDraw(new YScaleDraw);
scaleItemY->setBorderDistance(0);
scaleItemY->attach(this);
this->enableAxis(QwtPlot::yLeft, false);
QwtPlotScaleItem *scaleItemX =
new QwtPlotScaleItem(QwtScaleDraw::TopScale);
scaleItemX->setScaleDraw(new XScaleDraw);
scaleItemX->setBorderDistance(0);
scaleItemX->attach(this);
this->enableAxis(QwtPlot::xBottom, false);
To copy to clipboard, switch view to plain text mode
XScale is drawn at the top (instead of bottom) and YScale is disappeared. Actually it happens even if I don't override virtual void drawLabel (QPainter* painter, double value) const function and create empty subclass of QwtScaleDraw. Any idea what is going on here?
Bookmarks