vm
18th March 2014, 10:44
Hello everybody,
i have a large Qt (4.8.4 / linux, opensuse) code which displays some data. I need to extend the main display window by adding axis scale. This window has a zoom (through mouse wheel), so the scale must adapt depending on the zoom. I read qwt (6.1) is appropriate for this task. I am performing some simple tests with qwt on a simplified code, but i am not able to display this scale using QwtPlotScaleItem, although I am successful at using qwt to display some curves !.
Can you tell me what I am doing wrong with the scale ?
Here is a section of the code ...
//Set scene, pixmap and get an image of the data
scene = new QGraphicsScene(this);
pixmapItem = new QGraphicsPixmapItem();
scene->addItem(pixmapItem);
view = new QGraphicsView();
view->setScene(scene);
setCentralWidget(view);
imageSrc = new ImageSource();
pixmapItem->setPixmap(*imageSrc->nextImage());
QImage* imagerectangle;
imagerectangle = new QImage(27500,250,QImage::Format_ARGB32);
imagerectangle->fill(qRgba(0, 0, 0, 0));
// Set a Qpainter
QPainter* rectangle;
rectangle = new QPainter(imagerectangle);
//Pen properties
QPen lepen;
QRectF rect(5000,100,3000,50);
lepen.setColor(Qt::red);
lepen.setWidth(10);
// TEST QWT: OK work -> a curve is displayed *****************************
QwtPlotCurve d_curves;
QwtScaleMap xMap;
QwtScaleMap yMap;
xMap.setScaleInterval(0, 10000);
yMap.setScaleInterval(0, 250);
// Calculate values
double xval[10000];
double yval[10000];
for(int i=0; i<10000;i++)
{
xval[i] = i;
yval[i] = qSin(xval[i]) * qCos(2.0 * xval[i]) * 100 +101;
}
d_curves.setPen(QColor(Qt::yellow));
d_curves.setStyle(QwtPlotCurve::Lines);
d_curves.setRenderHint(QwtPlotItem::RenderAntialia sed);
d_curves.setCurveAttribute(QwtPlotCurve::Fitted);
d_curves.setRawSamples(xval, yval, 10000);
const QRect &r = contentsRect();
xMap.setPaintInterval(r.left(), r.right());
yMap.setPaintInterval(r.top(), r.bottom());
d_curves.draw(rectangle, xMap, yMap, r);
d_curves.show();
// So far this is good ! ************************************************
// add a scale to the plot. DOES NOT WORK nothing is displayed ????????????
QwtPlotScaleItem* echelle;
echelle = new QwtPlotScaleItem();
echelle->setAlignment(QwtScaleDraw::TopScale);
echelle->setBorderDistance(0);
echelle->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick,100);
echelle->scaleDraw()->setTickLength(QwtScaleDiv::MinorTick,50);
echelle->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Labels,true) ;
rectangle->setRenderHint(QPainter::Antialiasing,
echelle->testRenderHint(QwtPlotItem::RenderAntialiased) );
echelle->setVisible(TRUE);
echelle->draw(rectangle,xMap,yMap,r);
echelle->show();
// what is wrong here ??????????????????????
// add to scene
scene->addPixmap(QPixmap::fromImage(*imagerectangle));
Thank you very much for your help !
Val
i have a large Qt (4.8.4 / linux, opensuse) code which displays some data. I need to extend the main display window by adding axis scale. This window has a zoom (through mouse wheel), so the scale must adapt depending on the zoom. I read qwt (6.1) is appropriate for this task. I am performing some simple tests with qwt on a simplified code, but i am not able to display this scale using QwtPlotScaleItem, although I am successful at using qwt to display some curves !.
Can you tell me what I am doing wrong with the scale ?
Here is a section of the code ...
//Set scene, pixmap and get an image of the data
scene = new QGraphicsScene(this);
pixmapItem = new QGraphicsPixmapItem();
scene->addItem(pixmapItem);
view = new QGraphicsView();
view->setScene(scene);
setCentralWidget(view);
imageSrc = new ImageSource();
pixmapItem->setPixmap(*imageSrc->nextImage());
QImage* imagerectangle;
imagerectangle = new QImage(27500,250,QImage::Format_ARGB32);
imagerectangle->fill(qRgba(0, 0, 0, 0));
// Set a Qpainter
QPainter* rectangle;
rectangle = new QPainter(imagerectangle);
//Pen properties
QPen lepen;
QRectF rect(5000,100,3000,50);
lepen.setColor(Qt::red);
lepen.setWidth(10);
// TEST QWT: OK work -> a curve is displayed *****************************
QwtPlotCurve d_curves;
QwtScaleMap xMap;
QwtScaleMap yMap;
xMap.setScaleInterval(0, 10000);
yMap.setScaleInterval(0, 250);
// Calculate values
double xval[10000];
double yval[10000];
for(int i=0; i<10000;i++)
{
xval[i] = i;
yval[i] = qSin(xval[i]) * qCos(2.0 * xval[i]) * 100 +101;
}
d_curves.setPen(QColor(Qt::yellow));
d_curves.setStyle(QwtPlotCurve::Lines);
d_curves.setRenderHint(QwtPlotItem::RenderAntialia sed);
d_curves.setCurveAttribute(QwtPlotCurve::Fitted);
d_curves.setRawSamples(xval, yval, 10000);
const QRect &r = contentsRect();
xMap.setPaintInterval(r.left(), r.right());
yMap.setPaintInterval(r.top(), r.bottom());
d_curves.draw(rectangle, xMap, yMap, r);
d_curves.show();
// So far this is good ! ************************************************
// add a scale to the plot. DOES NOT WORK nothing is displayed ????????????
QwtPlotScaleItem* echelle;
echelle = new QwtPlotScaleItem();
echelle->setAlignment(QwtScaleDraw::TopScale);
echelle->setBorderDistance(0);
echelle->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick,100);
echelle->scaleDraw()->setTickLength(QwtScaleDiv::MinorTick,50);
echelle->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Labels,true) ;
rectangle->setRenderHint(QPainter::Antialiasing,
echelle->testRenderHint(QwtPlotItem::RenderAntialiased) );
echelle->setVisible(TRUE);
echelle->draw(rectangle,xMap,yMap,r);
echelle->show();
// what is wrong here ??????????????????????
// add to scene
scene->addPixmap(QPixmap::fromImage(*imagerectangle));
Thank you very much for your help !
Val