Results 1 to 6 of 6

Thread: qwt, how to fill area above a curve with color?

  1. #1
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question qwt, how to fill area above a curve with color?

    Hello,

    I would like to color the area above or under the curve with some color to indicate that these areas are infeasible. How can it be done?
    Look at the attached image, there is a red curve and the area above it shall be painted with another color.

    Thank you

    best regards
    Attached Images Attached Images

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

    Default Re: qwt, how to fill area above a curve with color?

    QwtPlotCurve::setBrush() + QwtPlotCurve::setBaseline()

    Uwe

  3. The following 2 users say thank you to Uwe for this useful post:

    rambo83 (19th November 2009), StepanKuzmin (5th July 2013)

  4. #3
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qwt, how to fill area above a curve with color?

    Thank you very much, Uwe. You are very helpful! It does exactly what I wanted!

  5. #4
    Join Date
    Jul 2013
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qwt, how to fill area above a curve with color?

    Thanks, Uwe! Is there any way to set different colors for positive and negative values like in the images above?

    wiggle.gifwiggleboth.jpg

  6. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,241
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qwt, how to fill area above a curve with color?

    Not easily - you would have to overload QwtPlotCurve::fillCurve().

    Copy the code you see in qwt_plot_curve.cpp and instead of doing one drawPolygon do it twice with different brushs. For the first call set a clip above the baseline - for the second a clip below the baseline.

    Uwe

  7. #6
    Join Date
    May 2014
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: qwt, how to fill area above a curve with color?

    Hi all,
    I try to fill the curve below and over the baseline with different color. I try to use the code that I found here and for clipping different regions it's ok.
    But I'm not been able to fill it with different color could someone help me. I try with setBrush(...) but nothing happen.
    Thanks miky.

    Qt Code:
    1. Qt Code: Switch view
    2. void Curve::fillCurve(QPainter *painter,
    3. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    4. const QRectF & canvasRect, QPolygonF & polygon) const
    5. {
    6. painter->save();
    7. QBrush *brush1 = new QBrush (Qt::green, Qt::SolidPattern);
    8. painter->setBrush(*brush1);
    9. painter->setClipRect(0,yMap.transform(baseline()),1000,1000,
    10. Qt::ReplaceClip);
    11. // QwtPlotCurve::fillCurve(painter, xMap, yMap, canvasRect, polygon);
    12.  
    13. painter->setClipRect(0,0,1000,yMap.transform(baseline()),
    14. Qt::ReplaceClip);
    15. QwtPlotCurve::fillCurve(painter, xMap, yMap, canvasRect, polygon);
    16. painter->restore();
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How to fill QLabel Circle with color
    By arunvv in forum Qt Programming
    Replies: 6
    Last Post: 8th January 2009, 08:46
  2. Compute the area under a curve
    By giusepped in forum Qwt
    Replies: 0
    Last Post: 26th December 2008, 06:56
  3. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25
  4. Replies: 9
    Last Post: 21st June 2007, 10:27
  5. How to fill the grid with the color?
    By merry in forum Qt Programming
    Replies: 3
    Last Post: 18th June 2007, 11:10

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.