Results 1 to 2 of 2

Thread: Linear gradient problem

  1. #1
    Join Date
    Nov 2012
    Location
    Kentucky, USA
    Posts
    46
    Thanks
    21
    Qt products
    Qt4
    Platforms
    Windows

    Default Linear gradient problem

    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.

    Qt Code:
    1. // code in the Canvas class:
    2. QPalette pal = palette();
    3.  
    4. QLinearGradient gradient;
    5.  
    6. gradient.setCoordinateMode( QGradient::StretchToDeviceMode );
    7.  
    8. gradient.setColorAt( 0.0, QColor( 100, 100, 100 ) );
    9. gradient.setColorAt( 1.0, QColor( 25, 25, 112 ) );
    10.  
    11. pal.setBrush( QPalette::Window, QBrush( gradient ) );
    12.  
    13. setPalette( pal );
    14.  
    15. // and set the canvas to the plot:
    16. QwtPlot::setCanvas(new Canvas());
    To copy to clipboard, switch view to plain text mode 
    I get the gradient ok, just not in the desired direction.
    Any help is appreciated.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Linear gradient problem

    Construct the QLinearGradiant using this constructor, and make sure that start and stop have same x coordinate
    Qt Code:
    1. QLinearGradient::QLinearGradient ( const QPointF & start, const QPointF & finalStop )
    To copy to clipboard, switch view to plain text mode 

    or

    use setStart(), setFinalStop(), to set the points with same x coordinate
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

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

    K4ELO (10th April 2013), rawfool (10th April 2013)

Similar Threads

  1. Linear analog display
    By CoderMan in forum Qt Programming
    Replies: 3
    Last Post: 27th February 2012, 20:30
  2. Curve brush with linear gradient?
    By liversedge in forum Qwt
    Replies: 2
    Last Post: 11th September 2011, 17:03
  3. Gradient fill problem
    By benzolo in forum Qt Programming
    Replies: 0
    Last Post: 6th September 2010, 08:29
  4. Drawing a line with a linear gradient effect
    By toutarrive in forum Qt Programming
    Replies: 4
    Last Post: 15th February 2010, 07:42
  5. QprogressBar Style Sheets: double linear gradient
    By Beppe in forum Qt Programming
    Replies: 6
    Last Post: 8th May 2009, 14:41

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.