Results 1 to 7 of 7

Thread: How to fill QLabel Circle with color

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to fill QLabel Circle with color

    I need to identify the color outside the paintEvent and fill that color to circle.
    Can u elaborate ? didnt get u

  2. #2
    Join Date
    Jun 2006
    Location
    San Diego, USA
    Posts
    95
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to fill QLabel Circle with color

    Normally what we will do to fill the color in widget with paintEvent is by using setPen & setBrush, as shown below.

    Qt Code:
    1. void paintEvent(QPaintEvent *event)
    2. {
    3. QPainter p(this);
    4. p.setPen(QPen(Qt::black, 1, Qt::SolidLine, Qt::RoundCap));
    5. p.setBrush(QBrush(Qt::black, Qt::SolidPattern));
    6. p.drawEllipse(0, 0, width() - 1, height() - 1);
    7. p.end();
    8. QLabel::paintEvent(event);
    9. }
    To copy to clipboard, switch view to plain text mode 
    Here in the above shown example I am filling circle with black color.

    But my problem is I have to fill the circle with random colors taken from some other functionality. I cannot pass that color into this paintEvent function. So I have to do some other things which fills color for the circle outside paintEvent functionality.

    So how to fill color for the circle ?
    Last edited by jpn; 7th January 2009 at 20:13. Reason: missing [code] tags

Similar Threads

  1. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 22:25
  2. Change color of a link in QLabel using Style Sheets?
    By codeslicer in forum Qt Programming
    Replies: 2
    Last Post: 15th April 2008, 11:00
  3. Replies: 9
    Last Post: 21st June 2007, 10:27
  4. How to fill the grid with the color?
    By merry in forum Qt Programming
    Replies: 3
    Last Post: 18th June 2007, 11:10
  5. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36

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
  •  
Qt is a trademark of The Qt Company.