[Qgis-developer] QgsRubberBand 1px shift

Radim Blazek radim.blazek at gmail.com
Mon May 2 07:13:22 EDT 2011


Hi,
I am observing QgsRubberBand 1px shift with GRASS region. You can
verify comparing a layer with full region extent (e.g. r.mapcalc
test=1 or v.in.region output=test) with current region. After a long
QGIS code inspection I have discovered quite strange piece of code in
QT:

qpaintengine_x11.cpp:

// use the same rounding as in qrasterizer.cpp (6 bit fixed point)
static const qreal aliasedCoordinateDelta = 0.5 - 0.015625;
[...]
    qreal offs = adjust_coords ? aliasedCoordinateDelta : 0.0;
[...]
            if (!X11->use_xrender || !(render_hints & QPainter::Antialiasing)) {
                translated_points[j].rx() =
qRound(translated_points[j].rx() + aliasedCoordinateDelta) + offs;
                translated_points[j].ry() =
qRound(translated_points[j].ry() + aliasedCoordinateDelta) + offs;
            }

using QPainter::Antialiasing hint in fact solves the problem:

--- src/gui/qgsmapcanvasitem.cpp        (revision 15861)
+++ src/gui/qgsmapcanvasitem.cpp        (working copy)
@@ -42,6 +42,7 @@
                               const QStyleOptionGraphicsItem * option,
                               QWidget * widget )
 {
+  painter->setRenderHint(QPainter::Antialiasing);
   paint( painter ); // call the derived item's drawing routines
 }

May I apply the patch? I hope that just setting the hint should not
harm but I don't want to break anything in QGIS core few days before
release.

Do you understand the aliasedCoordinateDelta???

Radim


More information about the Qgis-developer mailing list