Results 1 to 3 of 3

Thread: How to set QPainter Background color?

  1. #1
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default How to set QPainter Background color?

    Hi.
    I use QPainter.
    It starts off as white color as the background.
    I dont seem to find any function in QPainter to set the background color to be any other color. What is the right way to set the QPainter color to, say, green?

    Thanks!
    Marc

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to set QPainter Background color?

    QPainter::setBackground() looks the obvious candidate, but I don't think this method does what you expect. By default background pixels are not painted, leaving whatever was already in the background untouched, i.e. Qt::TransparentMode is the default backgroundMode(). Changing the background mode will only affect the background pixels in areas that are painted in certain ways, and not the canvas in general.

    If you want the general base colour of whatever you are painting on (your "It") to be something other than the default then you should fill it with a colour using QPainter::fillRect() (or make sure Qt does it by default).

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

    GG2013 (25th June 2013)

  4. #3
    Join Date
    Apr 2011
    Posts
    58
    Thanks
    1

    Default Re: How to set QPainter Background color?

    Will filling QPainter with fillRect slow down the entire draw process?
    And what do you mean make sure Qt does it by default? How do I do that?
    Thanks!

Similar Threads

  1. Background color
    By FelixB in forum Qwt
    Replies: 4
    Last Post: 24th June 2013, 08:03
  2. Replies: 13
    Last Post: 29th April 2009, 16:51
  3. How to get pixel color from QPainter ??
    By rameshg87 in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2008, 09:58
  4. Weird color problems related to QTextEdit and QPainter
    By Erlendhg in forum Qt Programming
    Replies: 5
    Last Post: 18th June 2007, 22:57
  5. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 16: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.