有什么方法可以消除pythonQt5

时间:2020-04-21 03:24:43

标签: python-3.x pyqt5

我只想删除图形场景中显示的图像上的颜色,所以当我选择第一个多边形时,有许多多边形相互绘制,所有超出该多边形的多边形都应该变得透明可见

如果有人向我推荐资源,我会有所帮助,

下面提到的代码是polygon.py的Qgraphics项

    def paint(self, painter=QPainter, option=QStyleOptionGraphicsItem,widget=QWidget):
        path = QPainterPath()
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)
        painter.setRenderHint(QPainter.SmoothPixmapTransform)
        self.setZ_value_list = []
        self.All_polygon_list=[]

        for item in self.papa.items():
            item.show()
            if isinstance(item, Polygon):
                self.setZ_value_list.append(item.z_value)
                polygon_oo=[(p.pos().x(), p.pos().y()) for p in item.handle_list]
                self.All_polygon_list.append(polygon_oo)

        self.temp_zvalue=max(self.setZ_value_list)+1
        if self.fill and self.closed:
            self.color.setAlpha(self.op)
            painter.setBrush(self.color)
            painter.setPen(QPen(QColor(0, 0, 0, 0)))

            if self.isSelected():
                self.less_than_z_value = []
                self.less_than_polygon=[]
                self.polygon_handles=[]


                painter.setBrush(QBrush(self.polygon_color, Qt.BDiagPattern)) 
                pen = QPen(QColor(Qt.red))
                pen.setWidth(self.pen_width)
                painter.setPen(pen)
                # painter.setPen(QPen(QColor(Qt.yellow)))
                painter.drawPolygon(self.poly)

                for item in self.papa.items():
                    if isinstance(item, Polygon):
                        if item == self:
                            item.setZValue(self.temp_zvalue)
                            item.show()

以下提到的代码来自“图形”场景,它在该场景上复制了多边形项目

    def mousePressEvent(self, event=QGraphicsSceneMouseEvent):

        pos = event.scenePos()

        if self.drag:
            return

        if self.image is not None:
            if not self.sceneRect().contains(pos):
                pos = self.correct_pos(pos)
            if not self.g_pixmap.contains(pos):
                pos = self.correct_pos(pos)

        if event.button() == Qt.LeftButton:
            if self.drawing and not self.drag:
                if self.current is None:
                    self.clear_mod_shapes()
                    self.current = Polygon(self)
                    self.current.setSelected(True)
                    self.current.addPoint(pos)
                    self.update()
                    return
                else:
                    self.current.addPoint(pos)
                    self.update()
                    return

            if self.editing:

                for i in self.shapes:
                    if i.isSelected():
                        self.selected = i
                        self.shape_selected.emit()
                        return

0 个答案:

没有答案