简体   繁体   中英

how to change color of QGraphicsEllipseItem when it selected?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM