[Qt-interest] Unnecessary Rounding from QRectF to GCRect?
Stephen Chu
stephen at ju-ju.com
Tue Mar 29 15:44:43 CEST 2011
Just find out this has much more impact than I originally thought.
One part of my project is using QGraphicsScene with inches as the unit.
That is QPointF(1, 0) is 1 inch to the right of the origin. This makes
conversion between pixels and physical length simple since all
conversions are done inside of the items.
That all works great until I tried it on the Mac. This rounding is
causing error up to 0.5 inch which in my case is typically 1200 pixels.
I did file a bug for this and hope for a quick solution:
<http://bugreports.qt.nokia.com/browse/QTBUG-18416>
Right now I am testing for graphics engine at runtime and switch to
QImage if it's Core Graphics. QImage doesn't have this rounding.
In article
<stephen-3EFC07.11212328032011 at r186-50-238-87.dialup.adsl.anteldata.net.
uy>,
Stephen Chu <stephen at ju-ju.com> wrote:
> 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