Results 1 to 4 of 4

Thread: How to create sections on a Qwt Plot

  1. #1
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Maemo/MeeGo

    Default How to create sections on a Qwt Plot

    Here's what I am looking to do, and I haven't really found a solution yet within the Qwt documentation.

    I would like to create 2 vertical lines on a Qwt Plot. I already have the plot functionality working as well as being able to plot points on the plot.

    So, in between these two lines I would like to change the background color for just that section and only that section. Once the line has been reached, I want the background color before and after the double line section to remain the same as the default background color already set.

    Does anyone know if this is this possible?

    p.s. the section would need to be behind the curves already created on the QwtPlot, in a way, transparent.

    Thanks in advance!
    Last edited by dvez43; 30th August 2011 at 18:26.

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to create sections on a Qwt Plot

    You can create a custom "RectanglePlotItem" class derived from QwtPlotItem and add instances of this class to your plot. It should draw a rectangle in the color of your section. By specifying the z-order you can draw this item behind the curve.

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

    Default Re: How to create sections on a Qwt Plot

    Something like this:

    Qt Code:
    1. class YourItem: public QwtPlotItem
    2. {
    3. public:
    4. YourItem():
    5. m_orientation( Qt::Horizontal ),
    6. m_pen( Qt::red ),
    7. m_brush( Qt::blue )
    8. {
    9. setZ( 0.0 );
    10. }
    11.  
    12. void setInterval( const QwtInterval &interval )
    13. {
    14. m_interval = interval;
    15. }
    16.  
    17. void setOrientation( Qt::Orientation orientation )
    18. {
    19. m_orientation = orientation;
    20. }
    21.  
    22. virtual int rtti() const
    23. {
    24. return QwtPlotItem::Rtti_PlotUserItem;
    25. }
    26.  
    27. virtual void draw( QPainter *painter,
    28. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    29. const QRectF &canvasRect ) const
    30. {
    31. if ( !m_interval.isValid() )
    32. return;
    33.  
    34. const double off = qMax( m_pen.widthF(), 1.0 );
    35.  
    36. QRectF rect;
    37. if ( m_orientation == Qt::Horizontal )
    38. {
    39. rect.setLeft( canvasRect.left() - off );
    40. rect.setRight( canvasRect.right() + off );
    41. rect.setTop( yMap.transform( m_interval.minValue() ) );
    42. rect.setBottom( yMap.transform( m_interval.maxValue() ) );
    43. }
    44. else
    45. {
    46. rect.setLeft( canvasRect.top() - off );
    47. rect.setRight( canvasRect.bottom() + off );
    48. rect.setLeft( xMap.transform( m_interval.minValue() ) );
    49. rect.setRight( xMap.transform( m_interval.maxValue() ) );
    50. }
    51.  
    52. rect = rect.normalized();
    53.  
    54. painter->setPen( m_pen );
    55. painter->setBrush( m_brush );
    56. painter->drawRect( rect );
    57.  
    58. }
    59.  
    60. private:
    61. Qt::Orientation m_orientation;
    62. QwtInterval m_interval;
    63. QPen m_pen;
    64. QBrush m_brush;
    65. };
    To copy to clipboard, switch view to plain text mode 
    Uwe

  4. #4
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    27
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to create sections on a Qwt Plot

    I'm using something like this, too.
    In my application I often need just to change these backgournd-areas; the plot-data stays the same.

    So how can I trigger this background draw-funktion without redrawing the whole curve?

Similar Threads

  1. Replies: 9
    Last Post: 12th May 2014, 02:25
  2. create a qwt plot
    By fantom in forum Qwt
    Replies: 3
    Last Post: 11th March 2011, 11:13
  3. Replies: 1
    Last Post: 1st February 2010, 16:13
  4. Replies: 4
    Last Post: 19th April 2007, 14:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.