View Full Version : QPixmap rendering: QTransform adds random shifts

26th June 2012, 10:04
I am rendering a QPixmap and several QPainterPath's through a QPainter object like this:

QPainter painter;
painter.drawPixmap(pix->corners, *(pix->pixmap), pix->pixmap->rect());
// more QPaiterPath objects are rendered
// paint other stuff

Between repaints the transformation transf is changed but all other data - especiall the pixmap and the paths - remains untouched.
I would expect, that the paths keep their relative alignment to the pixmap, no matter what transf is.

Problem: In certain zoom levels (usually quit large zoom levels, e.g. displaying one pixmap-pixel as about 300x300 screen pixels) the pixmap starts to shift erratically beneath the paths. Maxumin shifts are about plus minus one half of a pixmap-pixel (which translates to 150+ screen pixels !) with no obvioos ralation to the expected position. See the screenshots for reference. The blue and cyan squares are the highly magnified pixels of my pixmap and the thin black line is the path. Actually the diamond shaped path should be perfectly centered within the cyan colored pixel.

expected: http://image-upload.de/image/SmbrpD/17401b0ea9.png
faulty: http://image-upload.de/image/pPlNTK/2af9a87d87.png

I experimented with QPainter::.setRenderHint with no visible change whatsoever.

Any ideas highly appreciated!

27th June 2012, 10:07
QPainter::setRenderHint(QPainter::SmoothPixmapTran sform, true);
does solve the issue; my problem was that I called it before QPainter::begin(). If you do it right, it suddenly works :-)