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. Pixel accurate painting on Widget
Qt 6.11 is out! See what's new in the release blog

Pixel accurate painting on Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 331 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.
  • S Offline
    S Offline
    Simmania
    wrote on last edited by
    #1

    Hi,
    I need to draw lines that are pixel accurate.
    So when executing this code:

    QPainter painter(this);
    painter.setPen(QPen(QColor(20,20,20), 1));
    painter.drawLine(10,10,10,100);
    painter.drawLine(15,10,15,100);
    painter.drawLine(20,10,20,100);
    painter.drawLine(25,10,25,100);

    I expect 4 vertical lines of one bit wide.
    But what I get is this:

    verlines.JPG

    Lines of one pixel and lines of 2 pixels wide. How is that possible?
    How can I draw lines that are always 1 pixel width?
    Is there some other way to draw at pixel accuracy? Can I set individal pixels in an efficient way?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Simmania
      wrote on last edited by
      #2

      Solved!
      Seemed this was because there was a scale factor set for the screen I was drawing to.
      It is a pitty that this can lead to bad pixel drawing. I

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mpergand
        wrote on last edited by
        #3

        You may need to add:
        painter.setRenderHint(QPainter::Antialiasing,true);

        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