Results 1 to 5 of 5

Thread: QGraphicsItemChange not working for ItemPositionChange

  1. #1
    Join Date
    Mar 2016
    Posts
    16
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    3

    Default QGraphicsItemChange not working for ItemPositionChange

    I am trying out an example from
    http://www.informit.com/store/c-plus...-9780132354165

    Chap08/diagram.pro

    The program compiles, but does not work as advertised. When you move the nodes, the links are supposed to move with the nodes. I used the debugger and found out that it never hits the if condition in
    Qt Code:
    1. QVariant Node::itemChange(GraphicsItemChange change,
    2. const QVariant &value)
    3. {
    4. if (change == ItemPositionChange) {
    5. foreach (Link *link, myLinks)
    6. link->trackNodes();
    7. }
    8. return QGraphicsItem::itemChange(change, value);
    9. }
    To copy to clipboard, switch view to plain text mode 

    If I take the if condition out, I sort of get to move the links, but after clicking on the graphics scene.

    Any insight would be great into what the problem is.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: QGraphicsItemChange not working for ItemPositionChange

    Have you set the QGraphicsItem::ItemSendsGeometryChanges and maybe QGraphicsItem::ItemSendsScenePositionChanges flags on your Node instances? These flags are both off by default, which means you will not get itemChange events for ItemPositionChange and other transform changes.

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

    Narada (5th April 2016)

  4. #3
    Join Date
    Mar 2016
    Posts
    16
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    3

    Default Re: QGraphicsItemChange not working for ItemPositionChange

    That was it. Didn't know there was such a flag. Thank you very much.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: QGraphicsItemChange not working for ItemPositionChange

    Quote Originally Posted by Narada View Post
    That was it. Didn't know there was such a flag. Thank you very much.
    The example in the book had code for the position change handling but not for setting the flags?

    Cheers,
    _

  6. #5
    Join Date
    Mar 2016
    Posts
    16
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    3

    Default Re: QGraphicsItemChange not working for ItemPositionChange

    That's correct. However, at the time the book was written the flag was set automatically. Later Qt changed the default values ( around 4.7).

Similar Threads

  1. Replies: 7
    Last Post: 24th September 2012, 08:17
  2. Working with map
    By naptizaN in forum Newbie
    Replies: 4
    Last Post: 28th August 2012, 13:57
  3. MVC example not working
    By yyiu002 in forum Newbie
    Replies: 1
    Last Post: 30th June 2010, 01:07
  4. My first app not working
    By Noks in forum Newbie
    Replies: 6
    Last Post: 2nd February 2010, 17:34
  5. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 02:02

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
  •  
Qt is a trademark of The Qt Company.