+ Reply to Thread
Results 1 to 3 of 3

Thread: How to set QPainter Background color?

  1. #1

    Default How to set QPainter Background color?

    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?


  2. #2
    Join Date
    Mar 2009
    Brisbane, Australia
    Thanked 1,565 Times in 1,495 Posts
    Qt products
    Qt4 Qt5
    Unix/X11 Windows
    Wiki edits

    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

    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?

+ Reply to Thread

Similar Threads

  1. Background color
    By FelixB in forum Qwt
    Replies: 4
    Last Post: 24th June 2013, 07:03
  2. Replies: 13
    Last Post: 29th April 2009, 15:51
  3. How to get pixel color from QPainter ??
    By rameshg87 in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2008, 08:58
  4. Weird color problems related to QTextEdit and QPainter
    By Erlendhg in forum Qt Programming
    Replies: 5
    Last Post: 18th June 2007, 21:57
  5. QLabel background color
    By munna in forum Newbie
    Replies: 3
    Last Post: 1st May 2006, 15:36


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts