Results 1 to 6 of 6

Thread: QGraphicsView: per-item antialiasing specification?

  1. #1
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question QGraphicsView: per-item antialiasing specification?

    Hello,
    is it possibile to specify a per-item antialias rendering in a QGraphicsView? As far as I understand QGraphicsView::setRenderHint affects all of the items, but in my application some items would look nicer without aliasing.

    Thanks

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 333 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView: per-item antialiasing specification?

    You can use / not use aliasing in the QGraphicsItem::paint itself,, cant you ?

  3. The following user says thank you to aamer4yu for this useful post:

    mattc (3rd May 2009)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsView: per-item antialiasing specification?

    If you don't want to do all the drawings yourself, subclass you needed item and adjust the flags:

    Qt Code:
    1. void MyGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. painter->setRenderHint(painter->renderHint() /*...*/);
    4. YourBaseClass::paint(painter, option, widget);
    5. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to Lykurg for this useful post:

    mattc (3rd May 2009)

  6. #4
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: QGraphicsView: per-item antialiasing specification?

    Hello aamer4yu,
    somehow such a simple solution didn't cross my mind! Here is the working code:

    Qt Code:
    1. void MyGraphicItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
    2. {
    3. painter->setRenderHint(QPainter::Antialiasing);
    4. QGraphicsEllipseItem::paint(painter, option, widget);
    5. painter->setRenderHint(QPainter::Antialiasing, false);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Thank you very much.

  7. #5
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsView: per-item antialiasing specification?

    thanks Lykurg,
    I've seen your reply after posting. I removed the line restoring the painter state, and changed the first line to preserve existing render hints.

    Qt Code:
    1. void MyGraphicItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
    2. {
    3. painter->setRenderHints(painter->renderHints() | QPainter::Antialiasing);
    4. QGraphicsEllipseItem::paint(painter, option, widget);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Btw, browsing the docs I found some inconsistency about the render hints functions. From QPainter:

    The renderHints() function returns a flag that specifies the rendering hints that are set for this painter. Use the setRenderHint() function to set or clear the currently set RenderHints
    so, what is setRenderHint*s*() supposed to do? Also, no "renderHint()" in QPainter.

  8. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,004 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsView: per-item antialiasing specification?

    Quote Originally Posted by mattc View Post
    so, what is setRenderHint*s*() supposed to do? Also, no "renderHint()" in QPainter.
    Yeah, I was mixing up some things. It's:
    Qt Code:
    1. QPainter::setRenderHint ( RenderHint hint, bool on = true );
    To copy to clipboard, switch view to plain text mode 
    or
    Qt Code:
    1. QPainter::setRenderHints ( RenderHints hints, bool on = true );
    To copy to clipboard, switch view to plain text mode 
    with hints g.e. "QPainter::Antialiasing|QPainter::TextAntialiasing ".

Similar Threads

  1. QGraphicsView: restrict bbox of Item to bbox of scene?
    By piquadrat in forum Qt Programming
    Replies: 0
    Last Post: 2nd April 2009, 13:38
  2. MDI display Item in QGraphicsView
    By wisconxing in forum Qt Programming
    Replies: 1
    Last Post: 7th November 2008, 00:11
  3. View, Scene, Item and thread??
    By dungsivn in forum Qt Programming
    Replies: 5
    Last Post: 20th August 2008, 19:21
  4. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  5. QGraphicsView and item focus
    By Micawber in forum Qt Programming
    Replies: 3
    Last Post: 22nd June 2007, 20:36

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.