QGraphicsPathItem hoverEvents - 禁止在路径形成的区域上悬停 [英] QGraphicsPathItem hoverEvents - suppress hover on area formed by the path

查看:53
本文介绍了QGraphicsPathItem hoverEvents - 禁止在路径形成的区域上悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://www.dropbox.com/s/phven3rriv36893/graphicsview-pathitem.png?dl=0我想知道是否有办法让我的 QGraphicsPathItem 响应 mouseHoverEvents 到实际曲线而不是文档中看到的整个橙色区域.

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/pipe.png?dl=0在我的应用程序中,我没有看到实际形成路径的区域,因此我只想要一个悬停贝塞尔曲线时的 hoverEnterEvent(当然,当贝塞尔曲线离开时,还有一个 hoverLeaveEvent).

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).

这可以通过 QGraphicsPathItem 实现还是完全错误的方法?如果是,如何?如果不是,可以考虑用什么 QGraphics 对象替代?

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.

干杯,迈克尔

推荐答案

您需要重新实现 QGraphicsItem.shape 以返回更准确的曲线表示.默认实现为您提供了您发现的边界框.

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.

这篇关于QGraphicsPathItem hoverEvents - 禁止在路径形成的区域上悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆