选择后如何更改QGraphicsEllipseItem的颜色? [英] how to change color of QGraphicsEllipseItem when it selected?
问题描述
我使用python 2.7 + pyqt4.8
i use python 2.7 + pyqt4.8
我创建许多项目,例如 QGraphicsEllipseItem
和 QGraphicsRectItem
在我的场景中。我把它们都做成了不同的颜色。它们周围元素的分配似乎是有界的,我希望它们也将填充颜色更改为另一种颜色(白色)。
i create many items like QGraphicsEllipseItem
and QGraphicsRectItem
in my scene. I made them all different colors. the allocation of the elements around them appears bounding rect, and I would like that they also changed the fill color to another color (white). When removing the selection to return to the original color.
如何在选择后更改 QGraphicsEllipseItem
的颜色?
how to change color of QGraphicsEllipseItem
when it selected?
推荐答案
您应使用处理程序方法触发 QGraphicsEllipseItem
clicked信号我们在这里将其称为 ellipseClickHandler
,在其中您可以通过调用其setBrush方法来更改椭圆项目的颜色,例如:
You should trigger your QGraphicsEllipseItem
"clicked" signal with a handler method which we call it here ellipseClickHandler
where you change the color of your ellipse item by calling its setBrush method like this for instance:
def ellipseClickHandler(self, ellipseItem)
ellipseItem.setBrush(QBrush(QtCore.Qt.red, style = QtCore.Qt.SolidPattern))
这篇关于选择后如何更改QGraphicsEllipseItem的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!