Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter.drawLine missing half pixels
Qt 6.11 is out! See what's new in the release blog

QPainter.drawLine missing half pixels

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • GofferG Offline
    GofferG Offline
    Goffer
    wrote on last edited by
    #1

    Hello guys,

    I have a very weird problem, I am drawing 2 lines that are supposed to be in contact but there is a gap of roughly 1/2 pixel ...
    As you can see in the following code my line is 1 pixel and the gap is roughly half of its width ...

    pen = QtGui.QPen()
    pen.setStyle(QtCore.Qt.SolidLine)
    pen.setWidth(1)
    
    

    I won't post more code as it would be way too many lines and extracting few lines wouldn't mean anything out of context. I'm confirming that the start point of the 2nd line is exactly the same value as the end point of the 1st line.

    0_1507860316582_bug.jpg

    So how can it miss half a pixel ??? Am I missing some antialiasing parameters ? but on 1 pixel I don't know how it would produce any visible changes.

    I've noticed that it happens if both lines are vertical, if i have 1 vertical and 1 horizontal it works just fine.

    Have you guys ever had a similar problem ?

    Thx ! :)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      Do the lines start/end on exactly the same pixel, or on neighboring pixels?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kenchan
        wrote on last edited by
        #3

        So what cap type have you set on the pen?
        Qt::FlatCap
        Qt::SquareCap

        That might make the difference.

        1 Reply Last reply
        0
        • GofferG Offline
          GofferG Offline
          Goffer
          wrote on last edited by
          #4

          Thank your for your replies, I had a 1pixel offset before the 1st line and that's what caused this problem. BUT I am still having the same kind of problem.

          If i set my pen cap style to Flat, I have a very very small space like 1/10 (or less) of a pixel but I can see that space as the background is dark ...

          So I've tried Square cap but now I've the opposite problem, the lines are riding on top of each other and I can see them too, it looks better when I zoom in but worse when I zoom out ...

          Definetly looks better than before with Flat cap but not 100% there yet.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            Do you use antialiasing? (see QPainter::renderHints)?
            Can you try adding 0.5 to all vertical line coordinates?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved