Results 1 to 2 of 2

Thread: Filling an ellipse with a QRadialGradient brush

  1. #1
    Join Date
    Mar 2006
    Posts
    142
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Filling an ellipse with a QRadialGradient brush

    Hello,
    I would like to draw an ellipse and fill it with a QRadialGradient brush. So I have 2 questions:
    • what is the difference between focal and center points in a QRadialGradient?
    • here is my code, which draws a classical - empty - ellipse, what should I add to fill it with the selected brush?
      Qt Code:
      1. QRadialGradient rg(this->fire_point, this->fire_size);
      2. rg.setColorAt(0, Qt::red);
      3. rg.setColorAt(1, Qt::white);
      4. pen.setBrush(QBrush(rg));
      5. painter.setPen(pen);
      6. painter.drawEllipse(this->fire_point.x(), this->fire_point.y(), this->fire_size*2, this->fire_size*2);
      To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Forstinning, Germany
    Posts
    10
    Thanked 7 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Filling an ellipse with a QRadialGradient brush

    Question 2:
    You have to set the brush of the painter, not of the pen.
    The pen draws only the border.

    Qt Code:
    1. QRadialGradient rg(this->fire_point, this->fire_size);
    2. rg.setColorAt(0, Qt::red);
    3. rg.setColorAt(1, Qt::white);
    4. painter.setBrush(QBrush(rg));
    5. painter.drawEllipse(this->fire_point.x(), this->fire_point.y(), this->fire_size*2, this->fire_size*2);
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to hwerglmir for this useful post:

    Caius Aérobus (30th October 2008)

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.