PDA

View Full Version : Linear gradient problem



K4ELO
9th April 2013, 16:07
I have a Qwt canvas with a gradient which works diagonally, but I don't want the gradient to run from the upper left corner to the bottom right corner. I just want the gradient to run from top to bottom, so both top corners have the same color and both bottom corners have the same corner. Searching but can't find a way to do this.



// code in the Canvas class:
QPalette pal = palette();

QLinearGradient gradient;

gradient.setCoordinateMode( QGradient::StretchToDeviceMode );

gradient.setColorAt( 0.0, QColor( 100, 100, 100 ) );
gradient.setColorAt( 1.0, QColor( 25, 25, 112 ) );

pal.setBrush( QPalette::Window, QBrush( gradient ) );

setPalette( pal );

// and set the canvas to the plot:
QwtPlot::setCanvas(new Canvas());

I get the gradient ok, just not in the desired direction.
Any help is appreciated.

Santosh Reddy
10th April 2013, 08:57
Construct the QLinearGradiant using this constructor, and make sure that start and stop have same x coordinate

QLinearGradient::QLinearGradient ( const QPointF & start, const QPointF & finalStop )

or

use setStart(), setFinalStop(), to set the points with same x coordinate