简体   繁体   English

选择后如何更改QGraphicsEllipseItem的颜色?

[英]how to change color of QGraphicsEllipseItem when it selected?

i use python 2.7 + pyqt4.8 我使用python 2.7 + pyqt4.8

i create many items like QGraphicsEllipseItem and QGraphicsRectItem in my scene. 我在场景中创建了许多像QGraphicsEllipseItemQGraphicsRectItem这样的项目。 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? 选择后如何更改QGraphicsEllipseItem颜色?

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: 您应该使用处理程序方法触发QGraphicsEllipseItem “ clicked”信号,我们在这里将其ellipseClickHandler ,您可以在其中通过调用像这样的setBrush方法来更改椭圆项的颜色:

def ellipseClickHandler(self, ellipseItem)
    ellipseItem.setBrush(QBrush(QtCore.Qt.red, style = QtCore.Qt.SolidPattern))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单击/选中时,Spotfire按钮更改颜色 - Spotfire button change color when clicked / selected Tkinter 如何更改 treeview 所选项目的颜色 - Tkinter how to change the color of treeview selected items 如何自动更改 QListWidget 中所选项目的颜色 - how to automatically change the color of selected item in QListWidget 如何更改 pyqt5 QTableWidget 中选定或单击的单元格的背景颜色? - How to change background color of selected or clicked cell in a pyqt5 QTableWidget? 更改按钮的颜色(如果已选中或将其悬停) - Change color of a button if selected or hovered 如何使用下拉框动态更改所选类别的颜色? - How to dynamically change color of selected category using dropdown box? 如何更改 matplotlib 中选定点的颜色? - How do I change color of the selected points in matplotlib? 如何在openpyXL中为特定列(D)添加下拉按钮并在选择一个选项时更改特定单元格的背景颜色 - How to add drop down button for particular column (D) in openpyXL and change the background color of particular cell when one option is selected 更改图像中所选ROI的颜色 - Change the color of selected ROI in an image 如何在一个类中继承 QGraphicsRectItem 和 QGraphicsEllipseItem? - How can I subclass QGraphicsRectItem and QGraphicsEllipseItem in one class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM