PDA

View Full Version : Problems with limited mouseMoveEvent



dodgeit
10th October 2011, 11:08
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...


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())

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

wysota
10th October 2011, 12:39
Such things are usually done using QGraphcsItem::itemChange()