问题
i use python 2.7 + pyqt4.8
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.
how to change color of QGraphicsEllipseItem
when it selected?
回答1:
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))
来源:https://stackoverflow.com/questions/31650301/how-to-change-color-of-qgraphicsellipseitem-when-it-selected