zeus300
zeus300

Reputation: 1075

Preeventing QGraphicsItem's itemChanged

I have a QGraphicsItem that the user can drag around. I want to keep the item in the upper right quadrant of my scene, so I overrode mouseMoveEvent like this:

def mouseMoveEvent(self, event):
    if self.x() < 0:
        self.setPos(0, self.y())
    if self.y() + self.rect().height() > 0:
        self.setPos(self.x(), -self.rect().height())

Works like a charm, so far so good.

Now I use the itemChanged to kick off calculations when the item moves. Although I made my item stand still when it reaches my defined boundary, itemChanged gets called also when my mouse is in the 'forbidden zone', which is understandable. I would like to block this behavior based on the above checks. Since QGraphicsItem is not a QObject, blockSignals does not work here. Any idea how I can achieve this?

Upvotes: 0

Views: 334

Answers (1)

m. c.
m. c.

Reputation: 895

Personally I prefer use ItemChange(...) when working with scene view framework. Avoid using mouseMoveEvent.

To disable itemChange, you can set item to not movable.

{
    setFlag(QGraphicsItem::ItemSendsGeometryChanges , false);
...
    setFlag(QGraphicsItem::ItemSendsGeometryChanges , true);
}

Upvotes: 1

Related Questions