Results 1 to 5 of 5

Thread: QPainter::drawLine(): straight lines look aliased

  1. #1
    Join Date
    Jan 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QPainter::drawLine(): straight lines look aliased

    I'm trying to draw two single pixel lines onto a QImage with the following code:

    Qt Code:
    1. QPainter linePainter(currentImage);
    2. linePainter.setRenderHint(QPainter::Antialiasing, false);
    3. linePainter.setPen(QPen(Qt::red,1));
    4. linePainter.drawLine(xSize/2, 0, xSize/2, ySize);
    5. linePainter.drawLine(0, ySize/2, xSize, ySize/2);
    To copy to clipboard, switch view to plain text mode 

    The image is displayed on a QLabel like this:

    Qt Code:
    1. ccdDisplayLabel->setPixmap(QPixmap::fromImage(*currentImage));
    To copy to clipboard, switch view to plain text mode 

    However, as you can see from the attached image, somewhere along the line something bad happens. The lines should be one pixel wide and bright red, however, the vertical line looks weird. How can I fix this?

    CcdDialogCrosshairs.png

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainter::drawLine(): straight lines look aliased

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QPainter::drawLine(): straight lines look aliased

    If you are doing the data rendering with anti-aliasing on after drawing the red line, and it is directly adjacent to your red line, then the anti-aliasing may be overlaying the red line. Try turning off the data rendering... does the red line look right then? What happens if you render the data without anti-aliasing?

  4. #4
    Join Date
    Jan 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainter::drawLine(): straight lines look aliased

    Thanks for your replies. It seems the problem is due to Windows' remote desktop, not Qt. If I run the program while I'm in front of the actual computer, the lines appear as they're supposed to.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainter::drawLine(): straight lines look aliased

    You probably have a loosy compression scheme (like JPEG) for your remote desktop enabled. So it's not antialiasing, it's just simplified data.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 29th June 2011, 16:52
  2. Replies: 8
    Last Post: 28th January 2010, 06:45
  3. Qt 4.6 on Ubuntu, no colors and aliased
    By afail in forum Installation and Deployment
    Replies: 1
    Last Post: 8th January 2010, 11:17
  4. use Qpainter to draw lines + problem in my painter
    By ReSu in forum Qt Programming
    Replies: 4
    Last Post: 5th March 2008, 15:44
  5. QStringList straight to file
    By freak in forum Newbie
    Replies: 2
    Last Post: 13th June 2006, 22:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.