PDA

View Full Version : QPixmap rendering: QTransform adds random shifts



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


QPainter painter;
painter.begin(this);
painter.setWorldTransform(transf);
painter.drawPixmap(pix->corners, *(pix->pixmap), pix->pixmap->rect());
painter.drawPath(aPaiterPath1);
painter.drawPath(aPaiterPath2);
// more QPaiterPath objects are rendered
painter.setWorldTransform(QTransform());
// paint other stuff
painter.end();


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!

stryga42
27th June 2012, 10:07
solved:
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 :-)