I have a QImage that represents a blank piece of paper and a QPainter, which is used to paint onto this image. Sometimes, I will want to rotate/translate the QPainter before any paint operations, in order to paint onto this image in "Landscape" orientation.
Here is a simplified snippet of the code:
_image = new QImage(paperRect().size(), QImage::Format_RGB888);
_painter->begin(_image);
if (_orientation == QPrinter::Landscape)
{
_painter->translate(0, _image->height());
_painter->rotate(270);
}
// Painting operations here.
Unfortunately, this is not working as I had expected. It seems that even though the painter has been rotated, it is unaware of the "new" bounds it can paint within, thereby clipping to the "Portrait" size.
I have tried the following to no avail: Turning off clipping (_painter->setClipping(false);
), setting a new clip rect (_painter->setClipRect(0, 0, _image.height(), _image.width());
), and adjusting the window and viewport in various ways.
I have looked through the documentation of QPainter and QImage, and scoured the internet, but I haven't found this particular issue discussed before.
paperRect().size()
? If that is still set to Portrait format (e.g. 210x294 mm for A4), that would explain a lot. – JvO