PDA

View Full Version : qwt, how to fill area above a curve with color?



rambo83
19th November 2009, 07:59
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

Uwe
19th November 2009, 08:50
QwtPlotCurve::setBrush() + QwtPlotCurve::setBaseline()

Uwe

rambo83
19th November 2009, 09:45
Thank you very much, Uwe. You are very helpful! It does exactly what I wanted!

StepanKuzmin
5th July 2013, 07:24
Thanks, Uwe! Is there any way to set different colors for positive and negative values like in the images above?

92689269

Uwe
5th July 2013, 14:02
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

ConfaMiky
17th December 2014, 12:07
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: Switch view
void Curve::fillCurve(QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF & canvasRect, QPolygonF & polygon) const
{
painter->save();
QBrush *brush1 = new QBrush (Qt::green, Qt::SolidPattern);
painter->setBrush(*brush1);
painter->setClipRect(0,yMap.transform(baseline()),1000,1000 ,
Qt::ReplaceClip);
// QwtPlotCurve::fillCurve(painter, xMap, yMap, canvasRect, polygon);

painter->setClipRect(0,0,1000,yMap.transform(baseline()),
Qt::ReplaceClip);
QwtPlotCurve::fillCurve(painter, xMap, yMap, canvasRect, polygon);
painter->restore();

}