问题描述
我在 SO 中通过 @serge_gubenko 找到了这个例子.围绕 PyQt4 中的中心点移动 QGraphicsItem
I found this example by @serge_gubenko in SO.Moving a QGraphicsItem around a central point in PyQt4
我做了一些修改,最终得到:为什么我的 QGraphicsItem 不可选?
I did then some modifications to end up with:Why is my QGraphicsItem not selectable?
如果我运行这个例子(移动一个 QGraphicsItemPyQt4 中的中心点)并单击图形项,它会自动显示一个虚线框,表示它被选中.我准备了图片来展示效果,但由于我的声誉很低,我还不允许上传这些 ;)
If I run the example (Moving a QGraphicsItem around a central point in PyQt4) and click on the graphics item, it automatically shows up with a dashed frame which indicates that it is selected. I prepared images to show the effect, but due to my low reputation I am not yet allowed to upload those ;)
在我看来,虚线框的已选择指示"是以某种方式自动出现的.在我修改的示例中(为什么我的 QGraphicsItem 不可选?),这确实没有发生,我不知道为什么?
To me it looks that this "is selected indication" by the dashed frame comes automatically somehow.In my modified example (Why is my QGraphicsItem not selectable?), this does not happen and I can't figure out why?
推荐答案
您使用 QtGui.QGraphicsItem,因此您定义了 boundingRect 和 Paint 方法,其中使用了 Painter drawEllipse 方法.在您找到的第一个示例中,该类直接使用 QtGui.QGraphicsEllipseItem 并且它完全不同,因为这些方法已经定义.顺便说一下,我没有找到为什么在你的情况下没有绘制 boundingRect.
You use QtGui.QGraphicsItem, so you define the boundingRect and paint methods, where you used the painter drawEllipse method. In the first example you found, the class uses directly QtGui.QGraphicsEllipseItem and it does all the difference, because those methods are already defined. By the way I didn't find why the boundingRect is not drawn in your case.
这篇关于如何使选定的 qgraphicsitem 的边界矩形自动显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!