PDA

View Full Version : Paint an image excluding a rect



franco.amato
6th October 2022, 15:17
Good morning,
I have to color an image white without touching a specific internal area (an internal QRect contained in the image).
How can I do it?

d_stranz
6th October 2022, 17:41
Copy the QRect region to a separate QImage (QImage::copy()), fill the original image with white (QImage::fill()), then use QPainter::drawImage() to copy the saved image back into place.

You could also use clipping to define a clip path that excludes the rectangle (QPainter::setClipPath()) and then use QPainter::fillRect() to set the remainder to white. This will let you exclude non-rectangular regions, but it will probably be harder to get right.