Results 1 to 2 of 2

Thread: QPainter - fill rect with gradient

  1. #1
    Join Date
    Nov 2010
    Location
    Budapest, Hungary
    Posts
    125
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QPainter - fill rect with gradient

    Hi,

    I'm using QPainter for painting rectangles.

    This works:
    painter->fillRect(myQRect,Qt::red);

    But how can I define a gradient filling, like:
    painter->fillRect(myQRect,Qt::LinearGradientPattern);
    ?

    I tryed to google it, but no simple examples found.
    Szilvi

  2. The following user says thank you to szisziszilvi for this useful post:

    emobemo (3rd September 2014)

  3. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainter - fill rect with gradient

    Qt Code:
    1. QLinearGradient gradient(myQRect.topLeft(), myQRect.bottomRight(); // diagonal gradient from top-left to bottom-right
    2. gradient.setColorAt(0, Qt::white);
    3. gradient.setColorAt(1, Qt::red);
    4. painter->fillRect(myQRect, gradient);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. The following user says thank you to wysota for this useful post:

    emobemo (3rd September 2014)

Similar Threads

  1. QPainter fill artefact
    By koan in forum Qt Programming
    Replies: 0
    Last Post: 10th October 2010, 15:52
  2. Gradient fill problem
    By benzolo in forum Qt Programming
    Replies: 0
    Last Post: 6th September 2010, 08:29
  3. Fill mode using QPainter
    By lni in forum Qt Programming
    Replies: 7
    Last Post: 23rd March 2009, 18:03
  4. QPainter Gradient
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 12:53
  5. QSvgRenderer fill rule always evenOdd with gradient
    By mr.costa in forum Qt Programming
    Replies: 0
    Last Post: 24th April 2007, 17:04

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.