Results 1 to 1 of 1

Thread: [SOLVED] Unable to move QGraphicsItem (delta is always 0) when calculating using...

  1. #1
    Join Date
    Apr 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default [SOLVED] Unable to move QGraphicsItem (delta is always 0) when calculating using...

    Here's my mouseMoveEvent (PyQt5):
    Qt Code:
    1. def mouseMoveEvent(self, event):
    2. parentPos = self.mapToParent(event.pos())
    3. # parentPos = event.pos()
    4.  
    5. if self.lastParentPos == None:
    6. self.lastParentPos = parentPos
    7.  
    8. delta = parentPos - self.lastParentPos
    9. print(delta.x(), ", ", delta.y())
    10. self.setPos(self.pos() + delta)
    11.  
    12. if self.onPositionChange:
    13. self.onPositionChange(self, delta)
    14.  
    15. self.lastParentPos = parentPos
    To copy to clipboard, switch view to plain text mode 

    I've also tried doing this with scene coords and various combinations, with / without mapTo/From. What am I doing wrong? Thank you!


    Added after 18 minutes:


    This code hacks around it:

    def mouseMoveEvent(self, event):
    pos = event.scenePos()

    if self.lastPos == None:
    self.lastPos = pos

    delta = pos - self.lastPos
    self.setPos(self.pos() + delta)

    if self.onPositionChange:
    self.onPositionChange(self, delta)

    self.lastPos = pos

    def mouseReleaseEvent(self, event):
    self.lastPos = None
    Last edited by enjoysmath; 8th August 2015 at 19:10.

Similar Threads

  1. QGraphicsItem move
    By Ichi in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2013, 20:48
  2. Replies: 7
    Last Post: 29th November 2010, 20:20
  3. Child widget does not move along with its parent
    By starch in forum Qt Programming
    Replies: 8
    Last Post: 9th July 2009, 13:35
  4. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 09:41
  5. QGraphicsItem move question
    By mhoover in forum Qt Programming
    Replies: 2
    Last Post: 7th December 2006, 20:01

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.