[PyQt] setCursor does not seem to work as expected in graphicsScene/View

Christopher M. Nahler christopher.nahler at papermodels.at
Wed Aug 25 09:16:08 BST 2010

I have done more tests and found the following:

- I have tried self.update() in various locations of updateItems() and 
it did not change the behaviour.

- The changing of cursors always work with the item though.

- I have also tried commenting the item.update() line and this does not 
change the behaviour so I think update() is not relevant to cursor changes.

- I tried it with commenting the loop at the end where i change the item 
cursors and that changed the behaviour. So somehow changing the cursor 
of an item has an effect on the view.

Any ideas or tips? Is this a bug or am I doing something the wrong way? 
If I cannot get the cursors to work right I need to change my approach 
on how i tell the user which mode he is working in.


On 24.08.2010 16:03, Mark Summerfield wrote:
> Hi Christopher,
> I think one factor is that you call update() on the items after changing
> the cursor, but not on the view. I tried this:
>       def updateItems(self):
>           print("view updateItems")
>           m = self.scene().viewMode()
>           if m == MyScene.SELECTMODE:
>               print("is select mode")
>               itemCursor = Qt.OpenHandCursor
>           elif m == MyScene.EDITMODE:
>               print("is edit mode")
>               itemCursor = Qt.ForbiddenCursor
>           elif m == MyScene.DRAWMODE:
>               print("is draw mode")
>               itemCursor = Qt.CrossCursor
>           items = self.scene().items()
>           for item in items:
>               item.setCursor(itemCursor)
>               item.update()
>           self.setCursor(itemCursor)
>           self.update()
> which had an interesting effect, i.e., the view's cursor does change,
> but it doesn't work as I expected, and I don't have time to look into it
> further:-(
> [snip]

More information about the PyQt mailing list