views:

50

answers:

2

Is there a way to restrict the area where a QGraphicsItem like QRect can be moved when setFlag(ItemIsMovable) is set?

I'm new to pyqt and trying to find a way to move an item with the mouse, and the restrict it to only vertically/horizontally.

Thanks!

+1  A: 

You would probably need to reimplement the QGraphicsItem's itemChange() function. Pseudocode:

if (object position does not meet criteria):
    (move the item so its position meets criteria)

Repossitioning the item will cause itemChange to get called again, but that's ok because the item will be possitioned correctly and won't be moved again, so you'll not be stuck in an endless loop.

Simon Hibbs
+1  A: 
Moayyad Yaghi