Results 1 to 2 of 2

Thread: QPainter Gradient

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    860
    Thanks
    69
    Thanked 57 Times in 55 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QPainter Gradient

    Hi,
    I can make that a PainterPath fills with a Gradient.

    This is the paintEvent:
    Qt Code:
    1. QRectF qBoundingRect(0,0,width(),height());
    2. QPointF qCenter;
    3.  
    4. qCenter.setX(((double)width())/2);
    5. qCenter.setY(((double)height()/2);
    6.  
    7. QRadialGradient qGradientRadial; //I want to Light Green to Dark Green
    8. qGradientRadial1.setCenter(qCenter);
    9. qGradientRadial1.setColorAt(0.0,QColor(0,255,0));
    10. qGradientRadial1.setColorAt(1.0,QColor(0,120,0));
    11.  
    12. QPainterPath qPainterPathBones;
    13. qPainterPathBones.moveTo(qCenter);
    14. qPainterPathBones.arcTo(qBoundingRect,0.0,110); //From 0º to 110º
    15. qPainterPathBones.closeSubpath();
    16.  
    17. QPainter painter(this);
    18.  
    19. painter.setBrush(qGradientRadial1);
    20. painter.drawPath(qPainterPathBones);
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    860
    Thanks
    69
    Thanked 57 Times in 55 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPainter Gradient

    Hi,
    Sorry, forget this. I was reading LinearGradient doc and using RadialGradient.

    Thanks,
    Òscar Llarch i Galán

Similar Threads

  1. [qt4,win,g++] QPainter on a QGLWidget
    By jh in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2008, 07:29
  2. QPainter, scale(), and setFont()
    By c_07 in forum Qt Programming
    Replies: 11
    Last Post: 2nd January 2008, 20:46
  3. QPainter and QImage
    By beerkg in forum Newbie
    Replies: 3
    Last Post: 7th September 2006, 15:48
  4. Replies: 7
    Last Post: 20th March 2006, 21:03
  5. passing a QPainter object to widgets
    By vratojr in forum Qt Programming
    Replies: 9
    Last Post: 11th January 2006, 16:27

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.