user2746752
user2746752

Reputation: 1088

Disabled QGraphicsItem prevents scrolling of QGraphicsView

I have multiple QGraphicsItems with the ItemIsSelectable, ItemIsMovable and ItemSendsGeometryChanges flags.

Sometimes I want to disable selection and movement of those items, and I'm currently doing this by calling QGraphicsItem.setEnabled(False). However, when the cursor is on top of a disabled QGraphicsItem, the scroll wheel doesn't scroll the view anymore. I have tried to find a solution through Google, but I haven't found any working solutions.

So, my question is: Is there an easy way to *not* make disabled items prevent scrolling if the cursor is hovering over them?

If not, I can just write an own function that disables the mentioned flags instead of calling setEnabled() on the QGraphicsItem, but I'm still wondering why scrolling doesn't work, and if I really can't let disabled items ignore the scrolling event.

One thing I've tried already, is disabling Qt.MiddleButton with a setAcceptedMouseButtons() call, but that didn't seem to change anything.

My setup: Windows 7, Python 2.7.3 and PyQt4

Upvotes: 0

Views: 706

Answers (1)

Thalia
Thalia

Reputation: 14615

void QGraphicsItem::setEnabled(bool enabled)

Disabled items are visible, but they do not receive any events
Mouse events are discarded

That is the explanation why your mouse events - scroll wheel - are not working.
And why trying to change designation of mouse buttons doesn't make a difference - the item simply doesn't care :-)

If you want to disable movement and selection of a QGraphicsItem, the best way is to unset their QGraphicsItem::ItemIsSelectable and QGraphicsItem::ItemIsMovable flags.

This really seems simpler... As you probably already noticed.

The alternative - as the linked answer shows - is to install a scene event filter, have other items filter the disabled items events. The following question has good info:

Event filter on QGraphicsItem

Upvotes: 2

Related Questions