Results 1 to 8 of 8

Thread: QGraphicsScene artifacts

  1. #1
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QGraphicsScene artifacts

    I have a weird problem with graphics scene. I have a somewhat complicated scene composed of several custom QGraphicsItem derived objects. The items are nested into a tree with 3 levels. One of the items derives from QGraphicsTextItem. When its parent is being dragged over the scene, the text item leaves artifacts as shown on the attachment. When the same text item is moved to a simpler test case and its parent is being dragged, it does not leave the artifacts anymore.

    the implementation of the text item does not affect any of the boundingRect, shape, paint functions. I suspect that the problem is in one of the parent items. What might be the problem? How can the parent item affect the drawing of the child item?

    Screen shot 2011-02-15 at 1.50.27 AM.png

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsScene artifacts

    It certainly looks like a BoundingRect-related problem. Try making the BR quite large, just to see if the problem goes away or diminishes.

  3. #3
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QGraphicsScene artifacts

    should the bounding rect of the parent item include the bounding rects of the children items? What about the shape?

  4. #4
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene artifacts

    Yes it should. Shapes too if you can.
    What I usually do to debug is to draw the boudingRect() or shape() in the ::paint() method of the item, it's useful to see what's hapenning

  5. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsScene artifacts

    Quote Originally Posted by totem View Post
    Yes it should. Shapes too if you can.
    No true. bounding rect should contain whole area where current item is painted.
    This artifact can be rusult of:
    - to small boundingRect
    - painter not restored to initial state in paint method

  6. #6
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsScene artifacts

    Quote Originally Posted by MarekR22 View Post
    No true. bounding rect should contain whole area where current item is painted.
    "whole area where current item is painted" = "Current item bounding rect" + "children items bounding rects"

    no ?

  7. #7
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QGraphicsScene artifacts

    Quote Originally Posted by MarekR22 View Post
    This artifact can be rusult of:
    - to small boundingRect
    - painter not restored to initial state in paint method
    I always thought that the painter doesn't need to be restored in paint method, unless the view has the QGraphicsView::DontSavePainterState. I dont have this flag set. In fact, that text item that hold the string "Line" is drawn by the standard implementation of QGraphicsTextItem
    All the bounding rects of my items are properly calculated, and I always call painter->setClipRect(boundingRect()) to avoid any painting outside of the painter area. What else might cause the problem?

    From the image I attached it looks like the scene does not erase the spots that were covered by the item before the move. Do I need to call QGraphicsItem::prepareGeometryChange, or something like this before calling QGraphicsItem::setPos?

  8. #8
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QGraphicsScene artifacts

    QGraphicsItem::prepareGeometryChange should be called only when boundingRect is changing (on resize events for example).
    Instead cheat chat what can be wrong in the code, maybe you will show code with problematic graphics item (it doesn't look to be complicated).

    The fact that QGraphicsTextItem is not properly refresh doesn't mean that problem is with that item. This can be result of problems with other item.
    Last edited by MarekR22; 17th February 2011 at 14:23.

Similar Threads

  1. Too Much RAM used by QGraphicsScene
    By grabalon in forum Qt Programming
    Replies: 4
    Last Post: 6th May 2010, 16:38
  2. Bug in QGraphicsScene?
    By tbcpp in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2009, 15:23
  3. in QGraphicsScene matrix of other QGraphicsScene
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 15th February 2009, 18:27
  4. Rubber band artifacts?
    By mooreaa in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2008, 19:19
  5. Help on QGraphicsScene
    By Sandip in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2008, 15:20

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.