Results 1 to 5 of 5

Thread: Smooth lines in QGraphicsView

  1. #1
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Smooth lines in QGraphicsView

    Hi, how can I draw lines with smooth edges in QGraphicsView? I have strait dash line with 6px width and it looks really sharp and bad.

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Smooth lines in QGraphicsView

    You need to change :
    Qt::PenCapStyle
    Qt::PenJoinStyle

  3. #3
    Join Date
    Jul 2008
    Location
    London, UK
    Posts
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Smooth lines in QGraphicsView

    If you mean the angled line looks "jagged" when drawn at an angle you'll need to turn on "antialiasing" in the QGraphicsView e.g.

    Qt Code:
    1. graphicsView->setRenderHints(QPainter::Antialiasing);
    To copy to clipboard, switch view to plain text mode 

    Matthew.

  4. The following user says thank you to burnttoy for this useful post:

    JaRo999 (27th September 2009)

  5. #4
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Smooth lines in QGraphicsView

    Thank You both fot replies. Yogeshgokul - I was using that options already before I've wrote the post. Unfortunately they are not the way for "transition effect" between line and background. Burnttoy's code did the trick, however now some lines that should be black are gray - another problem to solve for the future

  6. #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: Smooth lines in QGraphicsView

    Quote Originally Posted by JaRo999 View Post
    Burnttoy's code did the trick, however now some lines that should be black are gray - another problem to solve for the future
    That's the way antialiasing works - it blurs the edges of the lines so if you have a black line with thickness of "1" it will become a black line with a thickness of "1" surrounded by two gray lines with a thickness of "1" each resulting in a gray line with a thickness of "3". It's either that or aliased lines.
    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: 16th September 2009, 11:23
  2. Replies: 0
    Last Post: 5th March 2009, 06:54
  3. how to draw lines on image using QGraphicsView in Qt4
    By madhavilatha in forum What's New in Qt 4.4
    Replies: 1
    Last Post: 25th July 2008, 00:32
  4. Smooth pixmap transform in QGraphicsView problem
    By spud in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2007, 16:47
  5. How to draw lines with the right width?
    By albanelporto in forum Qt Programming
    Replies: 3
    Last Post: 22nd November 2006, 11:51

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.