how to change color of QGraphicsEllipseItem when it selected?

怎甘沉沦 提交于 2019-12-14 03:07:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!