Results 1 to 6 of 6

Thread: Registering QGraphicsItem Movement (Drag)

  1. #1
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Registering QGraphicsItem Movement (Drag)

    Hi,

    I'm currently drawing some graphics items (actually QGraphicsPixmapItem) to a scene being shown by a view. I set each item to be movable, as follows

    this->setFlag( QGraphicsItem::ItemIsMovable, true );

    And it works fine. I'd like to be able to know when they are actually being moved, like call a function. It seems they they do not have signals/slots, nor can I get events to work. What is the best way to accomplish this?

    Thanks!

  2. #2
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Registering QGraphicsItem Movement (Drag)

    Sorry, I forgot to mention that I'm subclassing from QGraphicsPixmapItem.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Registering QGraphicsItem Movement (Drag)

    If you're already subclassing, the I guess you can look into http://doc.qt.nokia.com/4.6/qgraphic...tml#itemChange

  4. #4
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Registering QGraphicsItem Movement (Drag)

    Okay so I've added the following:

    Qt Code:
    1. QVariant ShipPart::itemChange ( GraphicsItemChange change, const QVariant & value )
    2. {
    3. if (change == ItemPositionChange && scene())
    4. {
    5. QPointF newPos = value.toPointF();
    6. //Stuff will happen here
    7. }
    8. return QGraphicsItem::itemChange(change, value);
    9. }
    To copy to clipboard, switch view to plain text mode 

    In debugging, I've found that the itemChange function gets called when I first add the item to the scene, as well as when I first make it visible. But when I move the item or just change it's position, it doesn't get called at all. Is that normal?

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Registering QGraphicsItem Movement (Drag)

    Yes, that's normal ;-)

    QGraphicsItem::ItemSendsGeometryChanges
    Set that flag.

    Edit: It's disabled for performance reasons

  6. The following user says thank you to tbscope for this useful post:

    Polnareff (27th May 2010)

  7. #6
    Join Date
    May 2010
    Posts
    41
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Registering QGraphicsItem Movement (Drag)

    Perfect Thanks!

Similar Threads

  1. Handle Drag & Drop Events with QGraphicsItem [SOLVED]
    By guilugi in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2010, 18:05
  2. Drag-Drop in QGraphicsItem
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 10th September 2009, 20:27
  3. Replies: 1
    Last Post: 25th February 2009, 00:34
  4. QtHelp Module - registering compressed help file gives error
    By Ankitha Varsha in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2008, 14:14
  5. Registering classe in QMetaType
    By rcintra in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2007, 22:26

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.