PDA

View Full Version : How to set QPainter Background color?



marc2050
29th April 2011, 03:55
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

ChrisW67
29th April 2011, 05:01
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).

marc2050
29th April 2011, 05:29
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!