lionel.s
7th July 2015, 10:04
Hello,
I try to have a zoom function which doesn't change the grid display. Major ticks have to stay on the same position. If I use QwtPlotZoomer with function zoom(QRect) the display of the grid is different.
So I have reimplement the QwtPlotZoomer::zoom(QRect) function and add this code :
float spaceX = (float)pRect.width()/5;
float spaceY = (float)pRect.height()/10;
QList<double> majorTicksX;
QList<double> majorTicksY;
for(int i=0; i<11; i++)
{
if(i<6)
majorTicksX.append(pRect.x() + spaceX*i);
majorTicksY.append(pRect.y() + spaceY*i);
}
QwtScaleDiv divX;
divX.setInterval(double(pRect.x()), double(pRect.x() + spaceX*5));
divX.setTicks(QwtScaleDiv::MajorTick, majorTicksX);
QwtScaleDiv divY;
divY.setInterval(double(pRect.y()), double(pRect.y() + spaceY*10));
divY.setTicks(QwtScaleDiv::MajorTick, majorTicksY);
plot()->setAxisScaleDiv(QwtPlot::xBottom, divX);
plot()->setAxisScaleDiv(QwtPlot::yLeft, divY);
static_cast<YourScaleDraw*>(plot()->axisScaleDraw(QwtPlot::xBottom))->min = pRect.x();
static_cast<YourScaleDraw*>(plot()->axisScaleDraw(QwtPlot::xBottom))->max = pRect.x()+ spaceX*5;
plot()->replot();
Class YourScaleDraw
class YourScaleDraw: public QwtScaleDraw
{
public:
virtual QwtText label( double v ) const
{
if(alignment() == LeftScale)
{
return QwtScaleDraw::label( int( v ) );
}
else if(alignment() == BottomScale)
{
return QwtScaleDraw::label(v);
}
}
virtual void drawLabel(QPainter* painter, double value) const
{
if(value == min && alignment() == BottomScale)
{
QRect boundingRect = boundingLabelRect(painter->font(), value);
boundingRect.setX(boundingRect.x() + boundingRect.width()/2);
boundingRect.setWidth(boundingRect.width()*2);
painter->fillRect(boundingRect, QColor(Qt::darkRed));
painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
}
else if(value == max && alignment() == BottomScale)
{
QRect boundingRect = boundingLabelRect(painter->font(), value);
boundingRect.setX(boundingRect.x() - boundingRect.width()/2);
boundingRect.setWidth(boundingRect.width() - boundingRect.width()/2);
painter->fillRect(boundingRect, QColor(Qt::darkRed));
painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
}
else
{
QRect boundingRect = boundingLabelRect(painter->font(), value);
painter->fillRect(boundingRect, QColor(Qt::darkRed));
painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
}
}
double min, max;
};
But this is not working with Qwt 6.0.1 but it is working with Qwt 6.1.0.
What can I do to make it work with Qwt 6.0.1.
Thanks
Lionel
I try to have a zoom function which doesn't change the grid display. Major ticks have to stay on the same position. If I use QwtPlotZoomer with function zoom(QRect) the display of the grid is different.
So I have reimplement the QwtPlotZoomer::zoom(QRect) function and add this code :
float spaceX = (float)pRect.width()/5;
float spaceY = (float)pRect.height()/10;
QList<double> majorTicksX;
QList<double> majorTicksY;
for(int i=0; i<11; i++)
{
if(i<6)
majorTicksX.append(pRect.x() + spaceX*i);
majorTicksY.append(pRect.y() + spaceY*i);
}
QwtScaleDiv divX;
divX.setInterval(double(pRect.x()), double(pRect.x() + spaceX*5));
divX.setTicks(QwtScaleDiv::MajorTick, majorTicksX);
QwtScaleDiv divY;
divY.setInterval(double(pRect.y()), double(pRect.y() + spaceY*10));
divY.setTicks(QwtScaleDiv::MajorTick, majorTicksY);
plot()->setAxisScaleDiv(QwtPlot::xBottom, divX);
plot()->setAxisScaleDiv(QwtPlot::yLeft, divY);
static_cast<YourScaleDraw*>(plot()->axisScaleDraw(QwtPlot::xBottom))->min = pRect.x();
static_cast<YourScaleDraw*>(plot()->axisScaleDraw(QwtPlot::xBottom))->max = pRect.x()+ spaceX*5;
plot()->replot();
Class YourScaleDraw
class YourScaleDraw: public QwtScaleDraw
{
public:
virtual QwtText label( double v ) const
{
if(alignment() == LeftScale)
{
return QwtScaleDraw::label( int( v ) );
}
else if(alignment() == BottomScale)
{
return QwtScaleDraw::label(v);
}
}
virtual void drawLabel(QPainter* painter, double value) const
{
if(value == min && alignment() == BottomScale)
{
QRect boundingRect = boundingLabelRect(painter->font(), value);
boundingRect.setX(boundingRect.x() + boundingRect.width()/2);
boundingRect.setWidth(boundingRect.width()*2);
painter->fillRect(boundingRect, QColor(Qt::darkRed));
painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
}
else if(value == max && alignment() == BottomScale)
{
QRect boundingRect = boundingLabelRect(painter->font(), value);
boundingRect.setX(boundingRect.x() - boundingRect.width()/2);
boundingRect.setWidth(boundingRect.width() - boundingRect.width()/2);
painter->fillRect(boundingRect, QColor(Qt::darkRed));
painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
}
else
{
QRect boundingRect = boundingLabelRect(painter->font(), value);
painter->fillRect(boundingRect, QColor(Qt::darkRed));
painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
}
}
double min, max;
};
But this is not working with Qwt 6.0.1 but it is working with Qwt 6.1.0.
What can I do to make it work with Qwt 6.0.1.
Thanks
Lionel