Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-26013

drawLine broken/inaccurate since Qt 4.8



    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.4
    • 4.8.0, 4.8.1
    • GUI: Painting
    • None
    • GNU/Linux (Ubuntu 12.04)
    • 87cd2d3530dfd3d7dc78b7dab50aefde87ca3b16 853ef83dfa6f07354276266816ff766bd8a16233


      When drawing lines, since Qt 4.8, the result is completely flawed on the pixel level.

      It appears as if there was some difference in the rounding technique used for horizontal and vertical pixel coordinates. You can see this easily when drawing a 3-pixel wide plus (i.e. a vertical line and a horizontal line, that should cross exactly in the center pixel). When moving this center pixel around, the plus distorts completely, sometimes becoming a T or an L or some other arrangement of the two lines.
      The attached line-bug.tar.gz is a small demo in which a plus and a cross are drawn magnified and follow the mouse cursor. (Untar it, then qmake; make)

      If you draw aliased, you see an interseting phenomenon on the cross: Move the cursor only to the right, not vertically. Watch the top left starting point of the diagonal. It doesn't move stepwise to the right as it should, but moves up, then down-right, then up, then down-right, etc.

      Further Observations:

      • Happens on all graphicssystems: raster, native (X11), opengl
      • Happens at least on Qt 4.8.0 and 4.8.1
      • Happens in both aliased and antialiased render hint modes of QPainter
      • Does not happen on Qt 4.7.4
      • Does not happen when discretizing the line data before passing it to the painter, i.e. passing a QLineF().toLine() instead of a QLineF()
        (This is not a valid workaround when you want to draw antialiased, because you lose floating point precision of start/end points)

      The attached BugAnimation.gif shows an animation of a cross moving horizontally. The top cross is drawn with Qt 4.7.4, the bottom one with Qt 4.8.1 with identical code.

      This bug may be the reason for what is reported in https://bugreports.qt-project.org/browse/QTBUG-25896, although comments (specifically by Samuel Rodal) suggest their problem might have something to do with antialiasing (or be improved by enabling it) and the graphicssystem. So maybe it is a different problem, because this isn't the case here.

      I consider this a critical bug, since when you can't rely on pixel exactness of simple line drawing, everything you draw will look crooked and small shapes just like indistinguishable specks of dirt.


        1. arrow_down_bad.png
          0.2 kB
        2. arrow_down_expected.png
          0.2 kB
        3. arrow_up_bad.png
          0.2 kB
        4. arrow_up_expected.png
          0.2 kB
        5. BugAnimation.gif
          37 kB
        6. line.tar.gz
          2 kB
        7. line-bug.tar.gz
          1 kB
        8. qt_bad_polygon_3X.png
          3 kB
        9. qt_bad_polygon.png
          3 kB
        10. qt4-pen-behavior.png
          15 kB
        11. qtbadpolygon.cpp
          1.0 kB
        12. qtguirasterproblem.zip
          1 kB
        13. sample.png
          0.4 kB
        For Gerrit Dashboard: QTBUG-26013
        # Subject Branch Project Status CR V



            rodal Samuel Rødal
            dermanu Emanuel Eichhammer
            14 Vote for this issue
            20 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes