Results 1 to 6 of 6

Thread: Graphics scene doesn't repaint properly

  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Graphics scene doesn't repaint properly

    I'm working with a graphics scene that can contain two types of QGraphicsItems: GraphicNodes and GraphicArcs. (Technically, GraphicNode inherits from QGraphicsRectItem because it made things easier for me but QGraphicsRectItems inherit from QGraphicsItem.) There are several types of GraphicNodes. Their only internal difference is their appearance.

    Nodes can be attached to each other using arrows. (I have yet to implement arrow heads.) When I move a node and then try to drag it where it previously was, the arrow is no longer drawn correctly as shown in these screenshots and this blurry video: http://www.youtube.com/watch?v=AQ-bvwUJ9TY

    fail.jpg

    fail1.jpg

    Any thoughts on why this might happen? I didn't use QGraphicsItem's built-in "draggable item" support because I wanted to create a "ghost" preview during dragging. For the bounding rectangle of the arrows, I used the smallest possible rectangle that contains all begin/end points of the line pieces that form the arrow. As long as arrows stay out of the game, everything seems fine.

  2. #2
    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: Graphics scene doesn't repaint properly

    If I understand Arrows are implemented by you. It looks like that QGraphicsItem::boundingRect of this arrow is incorrect or you do not call QGraphicsItem::prepareGeometryChange before value of boundingRect is changed.

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

    blooglet (15th April 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Graphics scene doesn't repaint properly

    Any thoughts on why this might happen?
    Looks like the algorithm used to draw the arrow is not error free.

    Without code however, its hard to say.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  5. #4
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Graphics scene doesn't repaint properly

    Quote Originally Posted by MarekR22 View Post
    It looks like that QGraphicsItem::boundingRect of this arrow is incorrect or you do not call QGraphicsItem::prepareGeometryChange before value of boundingRect is changed.
    Hmm... I didn't know that I had to call QGraphicsItem::prepareGeometryChange before changing the bounding rectangle. Quite stupid actually, because the doc for QGraphicsItem::boundingRect states that if you want to change the item's bounding rectangle, you must first call prepareGeometryChange(). Oops...

    Once again, I'm amazed at how you guys can pinpoint the cause of my problems with the little information I provide. Thanks!

  6. #5
    Join Date
    Apr 2011
    Posts
    7
    Qt products
    Qt Jambi
    Platforms
    Windows

    Default Re: Graphics scene doesn't repaint properly

    Are you able to post your code for this? I'm trying to do a similar thing with Arcs and Nodes. Are the nodes being logicially grouped in order as well?

    Any help would be awesome.

    Thanks

  7. #6
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Graphics scene doesn't repaint properly

    Sorry... I can't post any code because the program I'm working on is a project for a Computer Science course. What do you mean with "logical grouping"?

Similar Threads

  1. Using QLayout for layout in a graphics scene
    By ticica in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2009, 04:07
  2. graphics scene
    By dognzhe in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2009, 08:55
  3. QGraphicsView doesn't repaint itself - Help!
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2008, 14:08
  4. Buttons in Graphics Scene
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2007, 19:24
  5. QTreeWidget and Graphics scene
    By aamer4yu in forum Qt Programming
    Replies: 7
    Last Post: 21st December 2006, 17:24

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.