lnk
24th June 2014, 22:47
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:
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);
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() ) );
I wrote (for X shift) :
lbl.draw ( painter, QRect( QPoint( 0+(int)(labelSize.width()/2), 0 ), labelSize.toSize() ) );
and for Y shift:
lbl.draw ( painter, QRect( QPoint(0, 0+(int)(labelSize.height()/2) ), labelSize.toSize() ) );
Now I set scale draw and after that problems arise:
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);
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?
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:
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);
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() ) );
I wrote (for X shift) :
lbl.draw ( painter, QRect( QPoint( 0+(int)(labelSize.width()/2), 0 ), labelSize.toSize() ) );
and for Y shift:
lbl.draw ( painter, QRect( QPoint(0, 0+(int)(labelSize.height()/2) ), labelSize.toSize() ) );
Now I set scale draw and after that problems arise:
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);
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?