[PySide] SVG image follow mouse w/o drag and drop?

Kevin Cole dc.loco at gmail.com
Tue Aug 9 23:27:16 CEST 2016


On Fri, Aug 5, 2016 at 11:13 AM, Purma Jukka <jukka.purma at aalto.fi> wrote:

> Hi,
>
> You don’t have to do anything in QGraphicsView, you can have mousePressEvent in Image to toggle floating on and off. These events get QGraphicsMouseEvents as parameters and these have the information you need about position of cursor or mouse press. So, in short, remove mousePressEvent from viewPort and replace hoverMoveEvent in your Image with this and it will work:
>
>
>     def hoverMoveEvent(self, event):
>         if self.mobile:
>             print("Moving")
>             self.setPos(event.scenePos() - QPoint(self.width / 2, self.height / 2))
>
>     def mousePressEvent(self, event):
>         self.mobile = not self.mobile # Toggle mobility
>         super().mousePressEvent(event)
>
> Jukka
> --

Thanks. That worked. I cannot say that I really understand where
various methods are supposed to go yet, but you've helped me with my
immediate problem.



More information about the PySide mailing list