Hi all,

i'm trying to do a very simple thing but i'm not able to get the result i want ;(

I'm using QtSvg library. I want to display a shape and move it through the QGraphicsScene. I have done it and it works fine. The problem comes when i try to limit its movement, for example, if i want to limit its movement in x to 20 pixels from its original position.
The mouseMoveEvent function that i have implemented is show below where "self.posi" is the initial position of the shape...

Qt Code:
  1. class SvgElement(QtSvg.QGraphicsSvgItem):
  2. ...
  3. ...
  4. ...
  5.  
  6. def mouseMoveEvent (self, e):
  7. xValue = 0
  8. if self.pos().x() <= self.posi.x()+threshold and self.pos().x() >= self.posi.x()-threshold:
  9. super(SvgElement,self).mouseMoveEvent (e)
  10. else:
  11. if self.pos().x() >= self.posi.x()+threshold:
  12. xValue = self.posi.x()+self.threshold
  13. elif self.pos().x() < self.posi.x()-threshold:
  14. xValue = self.posi.x()-threshold
  15.  
  16. self.setPos(xValue, self.pos().y())
To copy to clipboard, switch view to plain text mode 

I'm not able to make it work, any idea what is it happening?
Any ideas will be appreciated