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...
...
...
...
def mouseMoveEvent (self, e):
xValue = 0
if self.pos().x() <= self.posi.x()+threshold and self.pos().x() >= self.posi.x()-threshold:
super(SvgElement,self).mouseMoveEvent (e)
else:
if self.pos().x() >= self.posi.x()+threshold:
xValue = self.posi.x()+self.threshold
elif self.pos().x() < self.posi.x()-threshold:
xValue = self.posi.x()-threshold
self.setPos(xValue, self.pos().y())
class SvgElement(QtSvg.QGraphicsSvgItem):
...
...
...
def mouseMoveEvent (self, e):
xValue = 0
if self.pos().x() <= self.posi.x()+threshold and self.pos().x() >= self.posi.x()-threshold:
super(SvgElement,self).mouseMoveEvent (e)
else:
if self.pos().x() >= self.posi.x()+threshold:
xValue = self.posi.x()+self.threshold
elif self.pos().x() < self.posi.x()-threshold:
xValue = self.posi.x()-threshold
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
Bookmarks