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 ...

Qt Code:
  1. //Set scene, pixmap and get an image of the data
  2. scene = new QGraphicsScene(this);
  3. pixmapItem = new QGraphicsPixmapItem();
  4. scene->addItem(pixmapItem);
  5.  
  6. view = new QGraphicsView();
  7. view->setScene(scene);
  8.  
  9. setCentralWidget(view);
  10.  
  11. imageSrc = new ImageSource();
  12. pixmapItem->setPixmap(*imageSrc->nextImage());
  13.  
  14. QImage* imagerectangle;
  15. imagerectangle = new QImage(27500,250,QImage::Format_ARGB32);
  16. imagerectangle->fill(qRgba(0, 0, 0, 0));
  17.  
  18. // Set a Qpainter
  19. QPainter* rectangle;
  20. rectangle = new QPainter(imagerectangle);
  21.  
  22. //Pen properties
  23. QPen lepen;
  24. QRectF rect(5000,100,3000,50);
  25. lepen.setColor(Qt::red);
  26. lepen.setWidth(10);
  27.  
  28.  
  29. // TEST QWT: OK work -> a curve is displayed *****************************
  30. QwtPlotCurve d_curves;
  31.  
  32. xMap.setScaleInterval(0, 10000);
  33. yMap.setScaleInterval(0, 250);
  34.  
  35. // Calculate values
  36. double xval[10000];
  37. double yval[10000];
  38. for(int i=0; i<10000;i++)
  39. {
  40. xval[i] = i;
  41. yval[i] = qSin(xval[i]) * qCos(2.0 * xval[i]) * 100 +101;
  42. }
  43.  
  44. d_curves.setPen(QColor(Qt::yellow));
  45. d_curves.setStyle(QwtPlotCurve::Lines);
  46. d_curves.setRenderHint(QwtPlotItem::RenderAntialiased);
  47. d_curves.setCurveAttribute(QwtPlotCurve::Fitted);
  48.  
  49. d_curves.setRawSamples(xval, yval, 10000);
  50.  
  51. const QRect &r = contentsRect();
  52.  
  53. xMap.setPaintInterval(r.left(), r.right());
  54. yMap.setPaintInterval(r.top(), r.bottom());
  55.  
  56. d_curves.draw(rectangle, xMap, yMap, r);
  57. d_curves.show();
  58. // So far this is good ! ************************************************
  59.  
  60.  
  61. // add a scale to the plot. DOES NOT WORK nothing is displayed ????????????
  62. QwtPlotScaleItem* echelle;
  63. echelle = new QwtPlotScaleItem();
  64. echelle->setAlignment(QwtScaleDraw::TopScale);
  65. echelle->setBorderDistance(0);
  66. echelle->scaleDraw()->setTickLength(QwtScaleDiv::MajorTick,100);
  67. echelle->scaleDraw()->setTickLength(QwtScaleDiv::MinorTick,50);
  68. echelle->scaleDraw()->enableComponent(QwtAbstractScaleDraw::Labels,true);
  69. rectangle->setRenderHint(QPainter::Antialiasing,
  70. echelle->testRenderHint(QwtPlotItem::RenderAntialiased) );
  71. echelle->setVisible(TRUE);
  72. echelle->draw(rectangle,xMap,yMap,r);
  73. echelle->show();
  74. // what is wrong here ??????????????????????
  75.  
  76.  
  77. // add to scene
  78. scene->addPixmap(QPixmap::fromImage(*imagerectangle));
To copy to clipboard, switch view to plain text mode 

Thank you very much for your help !

Val