Results 1 to 3 of 3

Thread: Overload QGraphicsItem Move in Scene

  1. #1
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    4
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Overload QGraphicsItem Move in Scene

    Hi. I have a class that inherits QGraphicsItem. I have set the QGraphicsItem::ItemIsMoveable flag in the class constructor so that I can move the item around the scene by grabbing and dragging. I want to overload the QGraphicsItem function responsible for this move functionality so that I can save the new position to a database whenever the item is moved in the scene. I have tried overloading the QGraphicsItem::setPos(), QGraphicsItem::moveBy(), and QGraphicsItem::setTransform() functions, but these do not seem to be used by the scene for moving. Can somebody please tell me what function is called by the scene during this type of move so that I know what function to overload? Thanks.

  2. #2
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Overload QGraphicsItem Move in Scene


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

    D Cell (16th March 2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    4
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Overload QGraphicsItem Move in Scene

    Thanks for the link. Once I finally got back to this issue, it sent me in the right direction. What I ended up doing was:

    in the class constructor:
    Qt Code:
    1. setFlag(QGraphicsItem::itemSendsScenePositionChanges);
    2. setFlag(QGrpahicsItem::itemSendsGeometryChanges);
    To copy to clipboard, switch view to plain text mode 

    in the overlaoded itemChange(GraphicsItemChange change, const QVariant &value) function:

    Qt Code:
    1. if ((change == QGraphicsItem::ItemScenePositionHasChanged || change == QGraphicsItem::ItemTransformHasChanged || change == QGraphicsItem::ItemPositionHasChanged) && scene())
    2. {
    3. //update position in database
    4. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsItem .. Scene .. View question?
    By DirtyBrush in forum Qt Programming
    Replies: 21
    Last Post: 19th October 2010, 09:12
  2. Can I copy a QGraphicsItem on my scene?
    By JesperWe in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2010, 21:21
  3. Update scene after moving QGraphicsItem
    By rogerholmes in forum Newbie
    Replies: 1
    Last Post: 19th January 2010, 05:08
  4. Can't move Items in the scene
    By maverick_pol in forum Qt Programming
    Replies: 2
    Last Post: 16th May 2008, 09:40
  5. Deleting a scene from QGraphicsItem mouseEvent
    By JonathanForQT4 in forum Qt Programming
    Replies: 5
    Last Post: 10th April 2007, 11:27

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.