Results 1 to 9 of 9

Thread: Qwt : QwtPlotZoomer with Qt 6.0.1, fixed grid

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    4

    Default Qwt : QwtPlotZoomer with Qt 6.0.1, fixed grid

    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 :

    Qt Code:
    1. float spaceX = (float)pRect.width()/5;
    2. float spaceY = (float)pRect.height()/10;
    3.  
    4. QList<double> majorTicksX;
    5. QList<double> majorTicksY;
    6. for(int i=0; i<11; i++)
    7. {
    8. if(i<6)
    9. majorTicksX.append(pRect.x() + spaceX*i);
    10.  
    11. majorTicksY.append(pRect.y() + spaceY*i);
    12. }
    13.  
    14. divX.setInterval(double(pRect.x()), double(pRect.x() + spaceX*5));
    15. divX.setTicks(QwtScaleDiv::MajorTick, majorTicksX);
    16. divY.setInterval(double(pRect.y()), double(pRect.y() + spaceY*10));
    17. divY.setTicks(QwtScaleDiv::MajorTick, majorTicksY);
    18.  
    19. plot()->setAxisScaleDiv(QwtPlot::xBottom, divX);
    20. plot()->setAxisScaleDiv(QwtPlot::yLeft, divY);
    21.  
    22. static_cast<YourScaleDraw*>(plot()->axisScaleDraw(QwtPlot::xBottom))->min = pRect.x();
    23. static_cast<YourScaleDraw*>(plot()->axisScaleDraw(QwtPlot::xBottom))->max = pRect.x()+ spaceX*5;
    24.  
    25. plot()->replot();
    To copy to clipboard, switch view to plain text mode 

    Class YourScaleDraw
    Qt Code:
    1. class YourScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. virtual QwtText label( double v ) const
    5. {
    6. if(alignment() == LeftScale)
    7. {
    8. return QwtScaleDraw::label( int( v ) );
    9. }
    10. else if(alignment() == BottomScale)
    11. {
    12. return QwtScaleDraw::label(v);
    13. }
    14. }
    15.  
    16. virtual void drawLabel(QPainter* painter, double value) const
    17. {
    18. if(value == min && alignment() == BottomScale)
    19. {
    20. QRect boundingRect = boundingLabelRect(painter->font(), value);
    21. boundingRect.setX(boundingRect.x() + boundingRect.width()/2);
    22. boundingRect.setWidth(boundingRect.width()*2);
    23. painter->fillRect(boundingRect, QColor(Qt::darkRed));
    24. painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
    25. }
    26. else if(value == max && alignment() == BottomScale)
    27. {
    28. QRect boundingRect = boundingLabelRect(painter->font(), value);
    29. boundingRect.setX(boundingRect.x() - boundingRect.width()/2);
    30. boundingRect.setWidth(boundingRect.width() - boundingRect.width()/2);
    31. painter->fillRect(boundingRect, QColor(Qt::darkRed));
    32. painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
    33. }
    34. else
    35. {
    36. QRect boundingRect = boundingLabelRect(painter->font(), value);
    37. painter->fillRect(boundingRect, QColor(Qt::darkRed));
    38. painter->drawText(boundingRect, Qt::AlignLeft, label(value).text());
    39. }
    40. }
    41.  
    42. double min, max;
    43. };
    To copy to clipboard, switch view to plain text mode 

    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

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

    Default Re: Qwt : QwtPlotZoomer with Qt 6.0.1, fixed grid

    What about disabling QwtPlotItem::ScaleInterest for your grid item - at least once you have your initial setup ?

    Uwe

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

    lionel.s (7th July 2015)

  4. #3
    Join Date
    Jun 2011
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    4

    Default Re: Qwt : QwtPlotZoomer with Qt 6.0.1, fixed grid

    It is an Histogram and I'm drawning data with a reimpl of drawColumn from QwtPlotHistogram.

    I'm trying to zoom -> change the x and y axis so the grid doesn't change. I always need 5 major ticks on the bottom axis and 10 on the left axis. But they should not move. Only the value of each ticks may change. Well it works with the Qwt 6.1.0 but the customer don't want to use another version than the 6.0.1. I don't use QwtPlotItem.

    Is it possible with Qwt 6.0.1 to have a fixe grid ?

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

    Default Re: Qwt : QwtPlotZoomer with Qt 6.0.1, fixed grid

    Instead of overloading QwtPlotZoomer::zoom() better overload QwtLinearScaleEngine::divideScale() - this is the right place for your first code snippet !
    The motivation behind the second seems to be to right/left align the min/max tick label, to avoid the extra space at the borders ?

    Which of your code snippets doesn't work with Qwt 6.0 ?

    Uwe

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

    lionel.s (7th July 2015)

Similar Threads

  1. Replies: 0
    Last Post: 9th March 2015, 12:47
  2. Replies: 2
    Last Post: 4th September 2014, 11:09
  3. Replies: 1
    Last Post: 5th March 2012, 06:34
  4. QwtPlotZoomer example
    By ken123 in forum Qwt
    Replies: 2
    Last Post: 20th October 2011, 15:20
  5. Replies: 1
    Last Post: 19th July 2010, 07:21

Tags for this Thread

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.