示例#1
0
def prepare_table_cells():
    """Prepare pollutant table cells"""
    red_cell = QTableWidgetItem()
    red_cell_brush = QBrush()
    red_cell_brush.setStyle(Qt.BrushStyle(Qt.DiagCrossPattern))
    red_cell_brush.setColor(QColor(255, 0, 0))
    red_cell.setBackground(red_cell_brush)
    green_cell = QTableWidgetItem()
    green_cell_brush = QBrush()
    green_cell_brush.setStyle(Qt.BrushStyle(Qt.Dense4Pattern))
    green_cell_brush.setColor(QColor(0, 255, 0))
    green_cell.setBackground(green_cell_brush)
    return red_cell, green_cell
示例#2
0
    def brushChanged(self):
        style = Qt.BrushStyle(
            self.brushStyleComboBox.itemData(
                self.brushStyleComboBox.currentIndex(), IdRole))

        if style == Qt.LinearGradientPattern:
            linearGradient = QLinearGradient(0, 0, 100, 100)
            linearGradient.setColorAt(0.0, Qt.white)
            linearGradient.setColorAt(0.2, Qt.green)
            linearGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(linearGradient))
        elif style == Qt.RadialGradientPattern:
            radialGradient = QRadialGradient(50, 50, 50, 70, 70)
            radialGradient.setColorAt(0.0, Qt.white)
            radialGradient.setColorAt(0.2, Qt.green)
            radialGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(radialGradient))
        elif style == Qt.ConicalGradientPattern:
            conicalGradient = QConicalGradient(50, 50, 150)
            conicalGradient.setColorAt(0.0, Qt.white)
            conicalGradient.setColorAt(0.2, Qt.green)
            conicalGradient.setColorAt(1.0, Qt.black)
            self.renderArea.setBrush(QBrush(conicalGradient))
        elif style == Qt.TexturePattern:
            self.renderArea.setBrush(QBrush(QPixmap(":/images/brick.png")))
        else:
            self.renderArea.setBrush(QBrush(Qt.green, style))
示例#3
0
    def set_colors(self, colors: List[Union[str, QColor]],
                   polygons: List[Union[int, str, NodePolygon]] = [],
                   brush_styles: List[Union[str, Qt.BrushStyle]] = []):
        self.lstColors.clear()
        for color, poly, brush_style in zip_longest(colors, polygons, brush_styles):
            if isinstance(color, str):
                color = QColor(color)

            if isinstance(poly, str):
                try:
                    poly = NodePolygon[poly]
                except KeyError:
                    poly = NodePolygon.Circle
            if isinstance(poly, int):
                poly = NodePolygon(poly)

            if isinstance(brush_style, str):
                brush_style = Qt.BrushStyle(int(brush_style))

            if color.isValid():
                item = ColorListWidgetItem()
                item.setBackground(color)
                if poly is not None:
                    item.setData(BaseColorMappingDialog.PolygonRole, poly)
                if brush_style is not None:
                    item.setData(BaseColorMappingDialog.BrushStyleRole, brush_style)
                self.lstColors.addItem(item)
示例#4
0
    def slotBrush(self, value):
        color = self.brushColorFrame.palette().color(QPalette.Window)
        style = Qt.BrushStyle(
            self.brushStyleComboBox.itemData(value, Qt.UserRole))

        if (style == Qt.LinearGradientPattern):
            linearGradient = QLinearGradient(0, 0, 400, 400)
            linearGradient.setColorAt(0.0, Qt.white)
            linearGradient.setColorAt(0.2, color)
            linearGradient.setColorAt(1.0, Qt.black)
            self.area.setBrush(linearGradient)
        elif style == Qt.RadialGradientPattern:
            radialGradient = QRadialGradient(200, 200, 80, 70, 70)
            radialGradient.setColorAt(0.0, Qt.white)
            radialGradient.setColorAt(0.2, Qt.green)
            radialGradient.setColorAt(1.0, Qt.black)
            self.area.setBrush(radialGradient)
        elif (style == Qt.ConicalGradientPattern):
            conicalGradient = QConicalGradient(200, 200, 30)
            conicalGradient.setColorAt(0.0, Qt.white)
            conicalGradient.setColorAt(0.2, color)
            conicalGradient.setColorAt(1.0, Qt.black)
            self.area.setBrush(conicalGradient)
        elif (style == Qt.TexturePattern):
            self.area.setBrush(QBrush(QPixmap("images/brick.png")))
        else:
            self.area.setBrush(QBrush(color, style))
 def setBrushStyle(self, value):
     """setBrushStyle
     """
     style = Qt.BrushStyle(
         int(self.brushStyleComboBox.itemData(value, Qt.UserRole)))
     self.paintArea.initPoint()
     self.paintArea.brush = QBrush(style)
示例#6
0
 def _makePixmap(self, width, height):
     pixmap = QPixmap(width, height)
     style = self.brushComboBox.itemData(self.brushComboBox.currentIndex())
     brush = QBrush(self.color, Qt.BrushStyle(style))
     painter = QPainter(pixmap)
     painter.fillRect(pixmap.rect(), Qt.white)
     painter.fillRect(pixmap.rect(), brush)
     return pixmap
示例#7
0
    def import_color_item(self, row: List[str]) -> Tuple:
        color = QColor(row[1][0])
        try:
            polygon_id = NodePolygon[row[1][1]] if len(row[1]) > 1 else NodePolygon.Circle
        except KeyError:
            polygon_id = NodePolygon.Circle
        brushstyle = Qt.BrushStyle(row[1][2]) if len(row[1]) > 2 else Qt.NoBrush

        if color.isValid():
            return color, polygon_id, brushstyle
示例#8
0
    def _makePixmap(self, width, height):  # setColor的子对象 函数调用 第一个问题就是大小
        pixmap = QPixmap(width,
                         height)  #Pixmap似乎是专门搞这种笔刷显示工具的,为什么不让Painter进行大小设置??
        style = self.brushComboBox.itemData(self.brushComboBox.currentIndex(
        ))  # 获取次目数据,然后获取该index的Data数据(text,text data)
        brush = QBrush(self.color, Qt.BrushStyle(style))  #将花纹和颜色添加到笔刷上
        painter = QPainter(pixmap)  #画布内嵌地图
        painter.fillRect(pixmap.rect(),
                         Qt.white)  # 底纹背景颜色,将其铺满画布 作为背景 其必须保持在前面而不是后面
        painter.fillRect(pixmap.rect(), brush)  # 将笔刷添加到Painter类的pixmap类型的画布中

        return pixmap
示例#9
0
    
    default = scene.nodes()[0].brush().color()
    
    scene.setNodesColors(colors)
    if len(colors) >= len(scene.nodes()):
        for i, node in enumerate(scene.nodes()):
            if colors[i].isValid():
                assert node.brush().color() == colors[i]
            else:
                assert node.brush().color() == default
        assert scene.nodesColors() == colors
    else:
        for node in scene.nodes():
            assert node.brush().color() == default
            
@pytest.mark.parametrize("brushes", [[QBrush(QColor(i), Qt.BrushStyle(j)) for i,j in zip(range(2, 12), range(2, 12))],
                                     [QBrush(QColor(i), Qt.BrushStyle(j)) for i,j in zip(range(2, 10), range(2, 10))],
                                     [QBrush(QColor(i)) for i in range(5)],
                                     [QBrush() for i in range(10)]])
def test_scene_set_nodes_overlay_brushes(scene, brushes):
    """Check that setNodesOverlayBrushes change overlay brushes for all nodes."""
       
    scene.setNodesOverlayBrushes(brushes)
    if len(brushes) >= len(scene.nodes()):
        for i, node in enumerate(scene.nodes()):
            assert node.overlayBrush() == brushes[i]
        assert scene.nodesOverlayBrushes() == brushes
    else:
        for node in scene.nodes():
            assert node.overlayBrush() == QBrush()