Results 1 to 3 of 3

Thread: Problems with QwtZoomer

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Problems with QwtZoomer

    Hi,
    I'm new to Qt/Qwt and I have a problem with the zoomer.
    Within my program I use geographical coordinates to visualize some 'z' values and therefore I use QwtPlot, especially depending on scales sometimes zooming is necessary.

    Here I use an adapted Zoomer class from the bode example:
    Qt Code:
    1. class MyZoomer: public QwtPlotZoomer
    2. {
    3. public:
    4. MyZoomer(QwtPlotCanvas *canvas):
    5. QwtPlotZoomer(canvas)
    6. {
    7. setTrackerMode(AlwaysOn);
    8.  
    9. }
    10.  
    11. virtual QwtText trackerText(const QwtDoublePoint &pos) const
    12. {
    13. QColor bg(Qt::white);
    14. #if QT_VERSION >= 0x040300
    15. bg.setAlpha(200);
    16. #endif
    17.  
    18. QwtText text = QwtPlotZoomer::trackerText(pos);
    19. text.setBackgroundBrush( QBrush( bg ));
    20. return text;
    21. }
    22. };
    To copy to clipboard, switch view to plain text mode 

    Zoom in and out works perfectly on the first loaded file.
    My problem appears if I load a second file. The initial plot shows the correct "new" coordinate space, but if I try to zoom in it collapse and ends up in a region far off and the Picker show (0.000,0.000). I tried to find some postings with a similar problem and I found:
    first
    second

    I think I've the same problem like kota, but the solutions to set a new zoomBase and/or to re-enable autoscaling doesn't work or I use it wrong.

    This is my complete code fragment:
    Qt Code:
    1. ui->PlotInitial->detachItems();
    2.  
    3. //** [Setup grid scheme]!
    4. ui->PlotInitial->setCanvasBackground(QColor(Qt::white));
    5. QwtPlotGrid *grid = new QwtPlotGrid;
    6. grid->enableXMin(true);
    7. grid->enableYMin(true);
    8. grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
    9. grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
    10. grid->attach(ui->PlotInitial);
    11. //** [Setup grid scheme]!
    12.  
    13.  
    14. QString appPath = QApplication::applicationDirPath();
    15. QString ColorMapFile = appPath + "/crp/topo.crp";
    16. vector< vector<double> > ColorMatrix = make_2DimVector <double>(256, 4);
    17. LoadFileIntoMatrix(ColorMapFile, ColorMatrix, 4, 256);
    18.  
    19. QwtArray< double > xVal, yVal;
    20.  
    21. double xmax = 0, ymax = 0, zmax = 0;
    22. double xmin = 10000000000, ymin = 10000000000, zmin = 10000000000;
    23.  
    24. for (int i = 0; i < Rows;i ++) {
    25. if (BigMatrix[i][0] < xmin) xmin = BigMatrix[i][0];
    26. if (BigMatrix[i][0] > xmax) xmax = BigMatrix[i][0];
    27. if (BigMatrix[i][1] < ymin) ymin = BigMatrix[i][1];
    28. if (BigMatrix[i][1] > ymax) ymax = BigMatrix[i][1];
    29.  
    30. if (BigMatrix[i][2] > zmax) zmax = BigMatrix[i][2];
    31. if (BigMatrix[i][2] < zmin) zmin = BigMatrix[i][2];
    32. }
    33.  
    34. double zKorrektur = 0;
    35. if (zmin < 0) {
    36. zmax = zmax + abs(zmin);
    37. zKorrektur = abs(zmin);
    38. }
    39.  
    40. for (int i = 0; i < Rows;i ++) {
    41. xVal.push_back(BigMatrix[i][0]);
    42. yVal.push_back(BigMatrix[i][1]);
    43.  
    44. double zVal = BigMatrix[i][2] + zKorrektur;
    45.  
    46. int ColorIndex = (zVal * 255) / zmax;
    47. // Insert new curves
    48. QwtSymbol symb;
    49. symb.setStyle(QwtSymbol::Ellipse);
    50.  
    51. QColor Color2Set = QColor::fromRgb(ColorMatrix[ColorIndex][1],ColorMatrix[ColorIndex][2],ColorMatrix[ColorIndex][3]);
    52. symb.setBrush(Color2Set);
    53. symb.setPen(Color2Set);
    54. symb.setSize(5);
    55.  
    56. QwtPlotCurve *cScatter = new QwtPlotCurve();
    57. cScatter->setStyle(QwtPlotCurve::NoCurve);
    58. cScatter->setSymbol(symb);
    59. cScatter->setData(xVal,yVal);
    60. cScatter->attach(ui->PlotInitial);
    61. xVal.clear();
    62. yVal.clear();
    63. }
    64.  
    65. //ui->PlotInitial->setAxisScale(QwtPlot::yLeft, ymin, ymax);
    66. //ui->PlotInitial->setAxisScale(QwtPlot::xBottom, xmin, xmax);
    67. //ui->PlotInitial->replot();
    68.  
    69. ui->PlotInitial->setAxisAutoScale(QwtPlot::yLeft);
    70. ui->PlotInitial->setAxisAutoScale(QwtPlot::xBottom);
    71.  
    72.  
    73. //** [Zoomfunctions!]
    74. zoomerI = new MyZoomer(ui->PlotInitial->canvas());
    75. zoomerI->setZoomBase();
    76.  
    77. #if QT_VERSION < 0x040000
    78. zoomerI->setMousePattern(QwtEventPattern::MouseSelect2,
    79. Qt::RightButton, Qt::ControlButton);
    80. #else
    81. zoomerI->setMousePattern(QwtEventPattern::MouseSelect2,
    82. Qt::RightButton, Qt::ControlModifier);
    83. #endif
    84. zoomerI->setMousePattern(QwtEventPattern::MouseSelect3,
    85. Qt::RightButton);
    86. //** [Zoomfunctions!]
    To copy to clipboard, switch view to plain text mode 


    I hope its not to confusing, but any help will be appreciated.

    Thank you and kind regards!

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with QwtZoomer

    What happened to your previous zoomer object ?

    If you already have one you don't have to create a second one - reset the zoom base of the existing one instead.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    Quereinsteiger (12th November 2010)

  4. #3
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with QwtZoomer

    Thats it, sometimes thinks are that easy.

Similar Threads

  1. Replies: 2
    Last Post: 23rd July 2010, 14:53
  2. Replies: 1
    Last Post: 16th March 2010, 09:29
  3. Replies: 1
    Last Post: 9th February 2010, 12:11
  4. Replies: 1
    Last Post: 19th May 2009, 11:14
  5. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.