[Qt-interest] Unnecessary Rounding from QRectF to GCRect?
Stephen Chu
stephen at ju-ju.com
Mon Mar 28 17:21:24 CEST 2011
My current project requires displaying some huge images. They are
typically 10s of Ks on both width and height. I need to scale them to
fit in view and also allow user to zoom in to parts of the image.
QGraphicsView handles most of the task for me nicely. I also only build
QPixmap at the exact screen resolution to speed up things. Basically
what I do is in paint(), calculate the current zoom level. Create a
QPixmap at exact that size. Then build my scaled image into it by
reading only needed lines from my file. Draw the result pixmap in the
supplied painter.
It works pretty well. But one issue came up on the Mac version of the
app: The pixmap is drawn stretched or shrunk by 1 line at times.
Resulting some annoying interference patterns. This doesn't happen in
Windows version so I figure it's the difference between raster and Core
Graphics engines.
I came to the line 971 in qpaintengine_mac.cpp (Qt 4.7.2) and it creates
a CGRect by rounding the supplied QRectF:
CGRect rect = CGRectMake(qRound(r.x()), qRound(r.y()),
qRound(r.width()), qRound(r.height()));
Taking out the qRound calls and my image fits perfectly. Just like the
Windows version.
So my question is: why is Qt rounding the numbers here? CGRect is made
up of 4 floats. It's got less precision than the doubles used in QRectF
but rounding it makes it much worse. What is the reason to round the
numbers? Should I report this as a bug?
Another (partial) solution is to force graphics engine to "raster" but
that messes up all widgets. :(
--
Stephen Chu
More information about the Qt-interest-old
mailing list