Search code examples
qtpyqtqgraphicsitemqgraphicsscenemousehover

QGraphicsPathItem hoverEvents - suppress hover on area formed by the path


https://www.dropbox.com/s/phven3rriv36893/graphicsview-pathitem.png?dl=0 I wonder if there's a way to make my QGraphicsPathItem respond to mouseHoverEvents to the actual curve instead of the whole orange area as seen in the docs.

https://www.dropbox.com/s/7m8w34nitp34sgf/pipes.png?dl=0 In my application I'm not seeing the area that actually forms the path and therefor I only want a hoverEnterEvent when the bezier curve is hovered (and a hoverLeaveEvent when the bezier is left of, course).

Is that possible to achieve with QGraphicsPathItem or is that a completely wrong approach? If yes, how? If not, what QGraphics object can be considered as a replacement?

If code is really needed, let me know.

Cheers, Michael


Solution

  • You need to reimplement QGraphicsItem.shape to return a more accurate representation of your curve. The default implementation gives you the bounding box as you've discovered.