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))
def paintEvent(self, event): p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) # Determine the width and height of the indicator w = self.width() h = self.height() # The smaller dimension determines our diameter d = min(w, h) * 0.9 r = d / 2 # Locate the center of the indicator circle center = QPointF(w / 2, h / 2) if self._on: # Gradient focus in the top left, fading from brighter to bright focus = center - QPointF(r, r) color0 = self._color color1 = self._color.darker(132) else: # Gradient focus in the bottom right, fading from darker to dark focus = center + QPointF(r, r) color0 = self._color.darker(800) color1 = self._color.darker(255) # Construct the gradient and draw the circle using it gradient = QRadialGradient(focus, d * 1.4, focus) gradient.setColorAt(0, color0) gradient.setColorAt(1, color1) p.setBrush(gradient) p.setPen(QColor(96, 96, 96)) p.drawEllipse(center, r, r)
def paintEvent(self, event): s = self.size() qp = QPainter() qp.begin(self) qp.setRenderHint(QPainter.Antialiasing, True) qp.setPen(Qt.NoPen) qp.setBrush(QColor(120, 120, 120)) qp.drawEllipse(0, 0, 20, 20) rg = QRadialGradient(int(self.width() / 2), int(self.height() / 2), 12) rg.setColorAt(0, QColor(255, 255, 255)) rg.setColorAt(0.6, QColor(255, 255, 255)) rg.setColorAt(1, QColor(205, 205, 205)) qp.setBrush(QBrush(rg)) qp.drawEllipse(1, 1, 18, 18) qp.setBrush(QColor(210, 210, 210)) qp.drawEllipse(2, 2, 16, 16) if self.__enabled: lg = QLinearGradient(3, 18, 20, 4) lg.setColorAt(0, QColor(255, 255, 255, 255)) lg.setColorAt(0.55, QColor(230, 230, 230, 255)) lg.setColorAt(0.72, QColor(255, 255, 255, 255)) lg.setColorAt(1, QColor(255, 255, 255, 255)) qp.setBrush(lg) qp.drawEllipse(3, 3, 14, 14) else: lg = QLinearGradient(3, 18, 20, 4) lg.setColorAt(0, QColor(230, 230, 230)) lg.setColorAt(0.55, QColor(210, 210, 210)) lg.setColorAt(0.72, QColor(230, 230, 230)) lg.setColorAt(1, QColor(230, 230, 230)) qp.setBrush(lg) qp.drawEllipse(3, 3, 14, 14) qp.end()
def draw_NI_extended_background(painter, c, w, h, bounding_rect, title_rect): """ :param painter: painter from paint event :param c: NodeInstance's theme color :param w: width :param h: height :param bounding_rect: NodeInstance's bounding rect :param title_rect: NI's title label's bounding rect """ background_color = QColor(31, 31, 36, 150) body_gradient = QRadialGradient( QPointF(bounding_rect.topLeft().x() + w, bounding_rect.topLeft().y() - h), pythagoras(2 * h, 2 * w)) body_gradient.setColorAt( 0, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 100)) body_gradient.setColorAt(0.7, background_color) body_gradient.setColorAt(1, background_color) painter.setBrush(body_gradient) painter.setBrush(QColor(28, 28, 28, 170)) pen = QPen(c.darker()) pen.setWidth(1) painter.setPen(pen) body_path = NIPainter_Ghostly.get_extended_body_path(5, w, h) painter.drawPath(body_path)
def drawArc(self, painter: QPainter, radius: int, angle: float, arc_color: QColor) -> None: painter.save() painter.setPen(Qt.NoPen) smallradius: int = radius - self.__radiusWidth maxRaidus: int = radius + self.__shadowWidth minRadius: int = smallradius - self.__shadowWidth # 采用圆形渐变,形成光晕效果 radialGradient: QRadialGradient = QRadialGradient( QPointF(0, 0), maxRaidus) color: QColor = arc_color lightColor: QColor = arc_color.name() color.setAlphaF(0) radialGradient.setColorAt(0, color) radialGradient.setColorAt(minRadius * 1.0 / maxRaidus, color) color.setAlphaF(0.5) radialGradient.setColorAt(smallradius * 1.0 / maxRaidus, color) radialGradient.setColorAt((smallradius + 1) * 1.0 / maxRaidus, lightColor) radialGradient.setColorAt((radius - 1) * 1.0 / maxRaidus, lightColor) radialGradient.setColorAt(radius * 1.0 / maxRaidus, color) color.setAlphaF(0) radialGradient.setColorAt(1, color) painter.setBrush(QBrush(radialGradient)) painter.drawPie(-maxRaidus, -maxRaidus, maxRaidus * 2, maxRaidus * 2, 90 * 16, int(-angle * 16)) painter.restore()
def paintEvent(self, e): painter = QPainter(self) painter.setRenderHint(QPainter.Antialiasing) the_size = min(self.width(), self.height()) gradient = QRadialGradient(QPointF(2 * the_size / 3, the_size / 3), the_size) if self.is_on: painter.drawPixmap( 0, 0, the_size, the_size, QIcon(str(FILE_PATH / "../resources/images/greenlight.svg")).pixmap( QSize(the_size, the_size))) else: painter.drawPixmap( 0, 0, the_size, the_size, QIcon(str(FILE_PATH / "../resources/images/redlight.svg")).pixmap( QSize(the_size, the_size))) # INNER Gradient # lgradien = QLinearGradient(the_size/2, 0, the_size/3, the_size) # lgradien.setColorAt(0.0, QColor(255, 255, 255, 200)) # lgradien.setColorAt(.5, QColor(255, 255, 255, 0)) # painter.setBrush(lgradien) # painter.setPen(Qt.NoPen) # painter.drawEllipse(0, 2, the_size, the_size/3) painter.end()
def setup(self): if not self.is_set: _edge = max([PartyConst.WIDTH, PartyConst.HEIGHT]) self._stars = np.random.randint(low=0, high=_edge, size=((_edge // 250)**2, 2)) self._pen_link = QPen(QColor('#351c75'), 2, Qt.SolidLine) self._lines = [] min_dist = 100 for _star in self._stars: for _sub_star in self._stars: if 0 < np.linalg.norm(_star - _sub_star) < min_dist: self._lines.append((_star, _sub_star)) _edge = max([PartyConst.WIDTH, PartyConst.HEIGHT]) _center = QPoint(self._galaxy.width() // 2, self._galaxy.height() // 2) _gradient = QRadialGradient(_center, _edge // 2) _gradient.setColorAt(1, QColor('#20124d')) _gradient.setColorAt(0, QColor('#351c75')) painter = QPainter(self._galaxy) painter.fillRect(0, 0, _edge, _edge, _gradient) painter.setPen(self._pen_link) for _xy1, _xy2 in self._lines: _xy1, _xy2 = QPoint(*_xy1), QPoint(*_xy2) painter.drawLine(_xy1, _xy2) _star_pens = [ QPen(QColor('#ffffff'), _size, Qt.SolidLine) for _size in [1, 2, 3, 4] ] for _i, (_x, _y) in enumerate(self._stars): _xy = QPoint(_x, _y) painter.setPen(_star_pens[_i % len(_star_pens)]) painter.drawPoint(_xy) painter.end() self._galaxy.save(IMAGE_GALAXY_PATH) self.is_set = True
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))
def draw_dark_extended_background(self, painter): c = self.parent_node.color # main rect body_gradient = QRadialGradient(self.boundingRect().topLeft(), pythagoras(self.height, self.width)) body_gradient.setColorAt( 0, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 200)) body_gradient.setColorAt( 1, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 0)) painter.setBrush(body_gradient) painter.setPen(Qt.NoPen) painter.drawRoundedRect(self.boundingRect(), 12, 12) header_gradient = QLinearGradient(self.get_header_rect().topRight(), self.get_header_rect().bottomLeft()) header_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 255)) header_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 0)) painter.setBrush(header_gradient) painter.setPen(Qt.NoPen) painter.drawRoundedRect(self.get_header_rect(), 12, 12)
def drawSlider(self, painter: QPainter) -> None: painter.save() painter.setPen(Qt.NoPen) if not self.__checked: painter.setBrush(self.__sliderColorOff) else: painter.setBrush(self.__sliderColorOn) if self.__buttonStyle == SwitchButton.ButtonStyle.ButtonStyle_Rect: sliderWidth: int = self.width() // 2 - self.__space * 2 sliderHeight: int = self.height() - self.__space * 2 sliderRect: QRect = QRect(self.__startX + self.__space, self.__space, sliderWidth , sliderHeight) painter.drawRoundedRect(sliderRect, self.__rectRadius, self.__rectRadius) elif self.__buttonStyle == SwitchButton.ButtonStyle.ButtonStyle_CircleIn: rect: QRect = QRect(0, 0, self.width(), self.height()) sliderWidth: int = min(rect.width(), rect.height()) - self.__space * 2 sliderRect: QRect = QRect(self.__startX + self.__space, self.__space, sliderWidth, sliderWidth) painter.drawEllipse(sliderRect) elif self.__buttonStyle == SwitchButton.ButtonStyle.ButtonStyle_CircleOut: sliderWidth: int = self.height() sliderRect: QRect = QRect(self.__startX, 0, sliderWidth, sliderWidth) color1: QColor = Qt.white if self.__checked else self.__bgColorOff color2: QColor = self.__sliderColorOn if self.__checked else self.__sliderColorOff radialGradient: QRadialGradient = QRadialGradient(sliderRect.center(), sliderWidth // 2) radialGradient.setColorAt(0, color1 if self.__checked else color2) radialGradient.setColorAt(0.5, color1 if self.__checked else color2) radialGradient.setColorAt(0.6, color2 if self.__checked else color1) radialGradient.setColorAt(1.0, color2 if self.__checked else color1) painter.setBrush(radialGradient) painter.drawEllipse(sliderRect) painter.restore()
def paintEvent(self, event): painter = qg.QPainter(self) option = qw.QStyleOption() option.initFrom(self) painter.setRenderHint(qg.QPainter.Antialiasing) x = option.rect.x() y = option.rect.y() height = option.rect.height() width = option.rect.width() # fill background painter.fillRect(x, y, width, height, self.background) gradient = QRadialGradient(float(width / 2), float(height / 2), float(height)) gradient.setColorAt(0.0, self.col1) gradient.setColorAt(0.5, self.col2) gradient.setColorAt(1.0, self.col3) painter.fillRect(x, y, width, height, gradient) # path line line_path = qg.QPainterPath() line_path.moveTo(0, 176) line_path.lineTo(width, 128) self.penTick.setCapStyle(qc.Qt.RoundCap) painter.setPen(self.penTick) painter.drawPath(line_path) # fill stripe painter.rotate(-5) painter.translate(float(50) * -1, float(-200)) painter.fillRect(x, y / 2, width * 2, (height - height / 2), self.stripe)
def paint(cls, painter, option, index): rect = QRectF(option.rect) w, h = option.rect.width(), option.rect.height() painter.save() if index.row() % 2 == 0: painter.fillRect(rect, QColor("#FFFFFF")) else: painter.fillRect(rect, QColor("#EFF5F5")) if option.state & QStyle.State_MouseOver: painter.fillRect(rect, QColor("#8CCDDE")) if option.state & QStyle.State_Selected: painter.fillRect(rect, QColor("#5FA4DD")) painter.drawText(rect.adjusted(0, 0, 0, 0), Qt.AlignVCenter, index.data(Qt.DisplayRole)[0]) if index.data(Qt.DecorationRole) == "true": pbrush = QPen(QBrush(QColor("#F2A6A6"), Qt.SolidPattern), 1) painter.setPen(pbrush) circlerect = QRectF(w - h - 1, h * index.row() + 1, h - 2, h - 2) gradient = QRadialGradient(circlerect.center(), h, circlerect.center()) gradient.setColorAt(0.0, QColor("#F2A6A6")) gradient.setColorAt(0.5, QColor("#EE8181")) gradient.setColorAt(1.0, QColor("#E55252")) brush = QBrush(gradient) painter.setBrush(brush) painter.setRenderHint(QPainter.Antialiasing) painter.drawEllipse(circlerect) pbrush = QPen(QBrush(QColor("#313131")), 20) painter.setPen(pbrush) painter.drawText(circlerect, Qt.AlignCenter, str(index.data(Qt.DisplayRole)[1])) painter.restore()
def draw_NI_extended_background(painter, c, w, h, bounding_rect, title_rect): """ :param painter: painter from paint event :param c: NodeInstance's theme color :param w: width :param h: height :param bounding_rect: NodeInstance's bounding rect :param title_rect: NI's title label's bounding rect """ # main rect body_gradient = QRadialGradient(bounding_rect.topLeft(), pythagoras(h, w)) body_gradient.setColorAt( 0, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 200)) body_gradient.setColorAt( 1, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 0)) painter.setBrush(body_gradient) painter.setPen(Qt.NoPen) painter.drawRoundedRect(bounding_rect, 12, 12) header_gradient = QLinearGradient( NIPainter_DarkStd.get_header_rect(w, h, title_rect).topRight(), NIPainter_DarkStd.get_header_rect(w, h, title_rect).bottomLeft()) header_gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(), 255)) header_gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), 0)) painter.setBrush(header_gradient) painter.setPen(Qt.NoPen) painter.drawRoundedRect( NIPainter_DarkStd.get_header_rect(w, h, title_rect), 12, 12)
def paint(self, painter: QPainter, option: QStyleOptionGraphicsItem, widget: Optional[QWidget] = ...): painter.setPen(QPen(Qt.NoPen)) painter.setBrush(Qt.darkGray) painter.drawEllipse(-7, -7, 20, 20) gradient = QRadialGradient(self._m_centerPos.x(), self._m_centerPos.y(), 10) if self.isSelected(): gradient.setCenter(3, 3) gradient.setFocalPoint(3, 3) gradient.setColorAt(1, QColor(Qt.yellow).lighter(120)) gradient.setColorAt(0, QColor(Qt.darkYellow).lighter(120)) else: gradient.setColorAt(0, Qt.yellow) gradient.setColorAt(1, Qt.darkYellow) painter.setBrush(gradient) painter.setPen(QPen(Qt.black, 0)) painter.drawEllipse(-10, -10, 20, 20)
def drawForeground(self, painter, rect): """Draws all connections and borders around selected items.""" pen = QPen() if Design.flow_theme == 'dark std': # pen.setColor('#BCBBF2') pen.setWidth(5) pen.setCapStyle(Qt.RoundCap) elif Design.flow_theme == 'dark tron': # pen.setColor('#452666') pen.setWidth(4) pen.setCapStyle(Qt.RoundCap) elif Design.flow_theme == 'ghostly' or Design.flow_theme == 'blender': pen.setWidth(2) pen.setCapStyle(Qt.RoundCap) # DRAW CONNECTIONS for ni in self.all_node_instances: for o in ni.outputs: for cpi in o.connected_port_instances: if o.type_ == 'data': pen.setStyle(Qt.DashLine) elif o.type_ == 'exec': pen.setStyle(Qt.SolidLine) path = self.connection_path( o.gate.get_scene_center_pos(), cpi.gate.get_scene_center_pos()) w = path.boundingRect().width() h = path.boundingRect().height() gradient = QRadialGradient(path.boundingRect().center(), pythagoras(w, h) / 2) r = 0 g = 0 b = 0 if Design.flow_theme == 'dark std': r = 188 g = 187 b = 242 elif Design.flow_theme == 'dark tron': r = 0 g = 120 b = 180 elif Design.flow_theme == 'ghostly' or Design.flow_theme == 'blender': r = 0 g = 17 b = 25 gradient.setColorAt(0.0, QColor(r, g, b, 255)) gradient.setColorAt(0.75, QColor(r, g, b, 200)) gradient.setColorAt(0.95, QColor(r, g, b, 0)) gradient.setColorAt(1.0, QColor(r, g, b, 0)) pen.setBrush(gradient) painter.setPen(pen) painter.drawPath(path) # DRAW CURRENTLY DRAGGED CONNECTION if self.dragging_connection: pen = QPen('#101520') pen.setWidth(3) pen.setStyle(Qt.DotLine) painter.setPen(pen) gate_pos = self.gate_selected.get_scene_center_pos() if self.gate_selected.parent_port_instance.direction == 'output': painter.drawPath( self.connection_path(gate_pos, self.last_mouse_move_pos)) else: painter.drawPath( self.connection_path(self.last_mouse_move_pos, gate_pos)) # DRAW SELECTED NIs BORDER for ni in self.selected_node_instances(): pen = QPen(QColor('#245d75')) pen.setWidth(3) painter.setPen(pen) painter.setBrush(Qt.NoBrush) size_factor = 1.2 x = ni.pos().x() - ni.boundingRect().width() / 2 * size_factor y = ni.pos().y() - ni.boundingRect().height() / 2 * size_factor w = ni.boundingRect().width() * size_factor h = ni.boundingRect().height() * size_factor painter.drawRoundedRect(x, y, w, h, 10, 10) # DRAW SELECTED DRAWINGS BORDER for p_o in self.selected_drawings(): pen = QPen(QColor('#a3cc3b')) pen.setWidth(2) painter.setPen(pen) painter.setBrush(Qt.NoBrush) size_factor = 1.05 x = p_o.pos().x() - p_o.width / 2 * size_factor y = p_o.pos().y() - p_o.height / 2 * size_factor w = p_o.width * size_factor h = p_o.height * size_factor painter.drawRoundedRect(x, y, w, h, 6, 6) painter.drawEllipse(p_o.pos().x(), p_o.pos().y(), 2, 2)
def getBrush(self, size, opacity, color, hardness, flow, spacing=1.0, jitter=0.0, orientation=0, pattern=None): """ initializes and returns a brush as a dictionary @param size: brush size @type size: int @param opacity: brush opacity, range 0..1 @type opacity: float @param color: @type color: QColor @param hardness: brush hardness, range 0..1 @type hardness: float @param flow: brush flow, range 0..1 @type flow: float @return: @rtype: dict """ s = float(self.baseSize) / 2 # set brush color if self.name == 'eraser': color = QColor(0, 0, 0, 0) else: op_max = 255 # 64 color = QColor(color.red(), color.green(), color.blue(), int(op_max * flow)) gradient = QRadialGradient(QPointF(s, s), s) gradient.setColorAt(0, color) gradient.setColorAt(hardness, color) if hardness < 1.0: # fade action to 0, starting from hardness to 1 if self.name == 'eraser': gradient.setColorAt(1, QColor(0, 0, 0, 255)) else: gradient.setColorAt(1, QColor(0, 0, 0, 0)) pxmp = self.basePixmap.copy() qp = QPainter(pxmp) # fill brush contour with gradient (pxmp color is (0,0,0,0) # outside of contourPath) qp.setCompositionMode(qp.CompositionMode_Source) qp.fillPath(self.contourPath, QBrush(gradient)) if self.preset is not None: ################################################ # we adjust the preset pixmap to pxmp size while keeping # its aspect ratio and we center it into pxmp ################################################ w, h = self.preset.width(), self.preset.height() # get the bounding rect of the scaled and centered preset # and the 2 complementary rects if w > h: rh = int(self.baseSize * h / w) # height of bounding rect m = int((self.baseSize - rh) / 2.0) # top and bottom margins r = QRect(0, m, self.baseSize, rh) r1 = QRect(0, 0, self.baseSize, m) r2 = QRect(0, rh + m, self.baseSize, m) else: rw = int(self.baseSize * w / h) # width of bounding rect m = int((self.baseSize - rw) / 2.0) # left and right margins r = QRect(m, 0, rw, self.baseSize) r1 = QRect(0, 0, m, self.baseSize) r2 = QRect(rw + m, 0, m, self.baseSize) # set opacity of r to that of preset qp.setCompositionMode(QPainter.CompositionMode_DestinationIn) qp.drawPixmap(r, self.preset) # paint the outside of r with transparent color pxmp1 = QPixmap(pxmp.size()) pxmp1.fill(QColor(0, 0, 0, 0)) qp.drawPixmap(r1, pxmp1) qp.drawPixmap(r2, pxmp1) qp.end() s = size / self.baseSize self.pxmp = pxmp.transformed(QTransform().scale( s, s).rotate(orientation)) # pxmp.scaled(size, size) pattern = pattern return { 'family': self, 'name': self.name, 'pixmap': self.pxmp, 'size': size, 'color': color, 'opacity': opacity, 'hardness': hardness, 'flow': flow, 'spacing': spacing, 'jitter': jitter, 'orientation': orientation, 'pattern': pattern, 'cursor': self.baseCursor }
def paintEvent(self, event): p = QPainter() p.begin(self) self._normalMap.render(p, event.rect()) p.setPen(Qt.black) # p.drawText(self.rect(), Qt.AlignBottom | Qt.TextWordWrap, "Map data CCBYSA 2009 OpenStreetMap.org contributors") p.end() if self.zoomed: dim = min(self.width(), self.height()) magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3) radius = magnifierSize / 2 ring = radius - 15 box = QSize(magnifierSize, magnifierSize) # reupdate our mask if self.maskPixmap.size() != box: self.maskPixmap = QPixmap(box) self.maskPixmap.fill(Qt.transparent) g = QRadialGradient() g.setCenter(radius, radius) g.setFocalPoint(radius, radius) g.setRadius(radius) g.setColorAt(1.0, QColor(255, 255, 255, 0)) g.setColorAt(0.5, QColor(128, 128, 128, 255)) mask = QPainter(self.maskPixmap) mask.setRenderHint(QPainter.Antialiasing) mask.setCompositionMode(QPainter.CompositionMode_Source) mask.setBrush(g) mask.setPen(Qt.NoPen) mask.drawRect(self.maskPixmap.rect()) mask.setBrush(QColor(Qt.transparent)) mask.drawEllipse(g.center(), ring, ring) mask.end() center = self.dragPos - QPoint(0, radius) center += QPoint(0, radius / 2) corner = center - QPoint(radius, radius) xy = center * 2 - QPoint(radius, radius) # only set the dimension to the magnified portion if self.zoomPixmap.size() != box: self.zoomPixmap = QPixmap(box) self.zoomPixmap.fill(Qt.lightGray) if True: p = QPainter(self.zoomPixmap) p.translate(-xy) self._largeMap.render(p, QRect(xy, box)) p.end() clipPath = QPainterPath() clipPath.addEllipse(QPointF(center), ring, ring) p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) p.setClipPath(clipPath) p.drawPixmap(corner, self.zoomPixmap) p.setClipping(False) p.drawPixmap(corner, self.maskPixmap) p.setPen(Qt.gray) p.drawPath(clipPath) if self.invert: p = QPainter(self) p.setCompositionMode(QPainter.CompositionMode_Difference) p.fillRect(event.rect(), Qt.white) p.end()
def testSetQPointF(self): grad = QRadialGradient() grad.setCenter(QPointF(1, 2)) self._compare(grad.center(), (1.0, 2.0))
def __init__(self, targetImage=None, axeSize=500, layer=None, parent=None, mainForm=None): super().__init__(targetImage=targetImage, axeSize=axeSize, layer=layer, parent=parent, mainForm=mainForm) graphicsScene = self.scene() ######### # L curve ######### cubic = activeCubicSpline(axeSize) graphicsScene.addItem(cubic) graphicsScene.cubicR = cubic cubic.channel = channelValues.L # get histogram as a Qimage cubic.histImg = graphicsScene.layer.inputImg().histogram(size=graphicsScene.axeSize, bgColor=graphicsScene.bgColor, range=(0, 1), chans=channelValues.L, mode='Lab') # L curve use the default axes cubic.axes = graphicsScene.defaultAxes cubic.initFixedPoints() cubic.axes.setVisible(False) cubic.setVisible(False) ########## # a curve (Green--> Magenta axis) ######### cubic = activeCubicSpline(axeSize) graphicsScene.addItem(cubic) graphicsScene.cubicG = cubic cubic.channel = channelValues.a cubic.histImg = graphicsScene.layer.inputImg().histogram(size=graphicsScene.axeSize, bgColor=graphicsScene.bgColor, range=(-100, 100), chans=channelValues.a, mode='Lab') # add specific axes gradient = QRadialGradient() gradient.setCenter(QPoint(0, 1)) gradient.setRadius(axeSize*1.4) gradient.setColorAt(0.0, Qt.green) gradient.setColorAt(1.0, Qt.magenta) cubic.axes = self.drawPlotGrid(axeSize, gradient) graphicsScene.addItem(cubic.axes) cubic.initFixedPoints() cubic.axes.setVisible(False) cubic.setVisible(False) # b curve (Blue-->Yellow axis) cubic = activeCubicSpline(axeSize) graphicsScene.addItem(cubic) graphicsScene.cubicB = cubic cubic.channel = channelValues.b cubic.histImg = graphicsScene.layer.inputImg().histogram(size=graphicsScene.axeSize, bgColor=graphicsScene.bgColor, range=(-100, 100), chans=channelValues.b, mode='Lab') # add specific axes gradient.setColorAt(0.0, Qt.blue) gradient.setColorAt(1.0, Qt.yellow) cubic.axes = self.drawPlotGrid(axeSize, gradient) graphicsScene.addItem(cubic.axes) cubic.initFixedPoints() cubic.axes.setVisible(False) cubic.setVisible(False) # set current to L curve and axes graphicsScene.cubicItem = graphicsScene.cubicR graphicsScene.cubicItem.setVisible(True) graphicsScene.cubicItem.axes.setVisible(True) # buttons pushButton1 = QPushButton("Reset Current") pushButton1.move(100, 20) pushButton1.adjustSize() pushButton1.clicked.connect(self.resetCurve) graphicsScene.addWidget(pushButton1) pushButton2 = QPushButton("Reset All") pushButton2.move(100, 50) pushButton2.adjustSize() pushButton2.clicked.connect(self.resetAllCurves) graphicsScene.addWidget(pushButton2) # options options = ['L', 'a', 'b'] self.listWidget1 = optionsWidget(options=options, exclusive=True) self.listWidget1.setGeometry(0, 10, self.listWidget1.sizeHintForColumn(0) + 5, self.listWidget1.sizeHintForRow(0) * len(options) + 5) graphicsScene.addWidget(self.listWidget1) # selection changed handler curves = [graphicsScene.cubicR, graphicsScene.cubicG, graphicsScene.cubicB] curveDict = dict(zip(options, curves)) def onSelect1(item): cubicItem = self.scene().cubicItem cubicItem.setVisible(False) cubicItem.axes.setVisible(False) self.scene().cubicItem = curveDict[item.text()] self.scene().cubicItem.setVisible(True) self.scene().cubicItem.axes.setVisible(True) # Force to redraw histogram self.scene().invalidate(QRectF(0.0, -self.scene().axeSize, self.scene().axeSize, self.scene().axeSize), QGraphicsScene.BackgroundLayer) self.listWidget1.onSelect = onSelect1 # set initial selection to L item = self.listWidget1.items[options[0]] item.setCheckState(Qt.Checked) self.listWidget1.select(item) self.setWhatsThis("""<b>Lab curves</b><br>""" + self.whatsThis()) def f(): l = graphicsScene.layer l.applyToStack() l.parentImage.onImageChanged() self.scene().cubicR.curveChanged.sig.connect(f) self.scene().cubicG.curveChanged.sig.connect(f) self.scene().cubicB.curveChanged.sig.connect(f)
fermatSpiral1 = QCPCurve(customPlot.xAxis, customPlot.yAxis) fermatSpiral1.setData(dataSpiral1X, dataSpiral1Y) fermatSpiral2 = QCPCurve(customPlot.xAxis, customPlot.yAxis) fermatSpiral2.setData(dataSpiral2X, dataSpiral2Y) deltoidRadial = QCPCurve(customPlot.xAxis, customPlot.yAxis) deltoidRadial.setData(dataDeltoidX, dataDeltoidY) # color the curves: fermatSpiral1.setPen(QPen(Qt.blue)) fermatSpiral1.setBrush(QBrush(QColor(0, 0, 255, 20))) fermatSpiral2.setPen(QPen(QColor(255, 120, 0))) fermatSpiral2.setBrush(QBrush(QColor(255, 120, 0, 30))) radialGrad = QRadialGradient(QPointF(310, 180), 200) radialGrad.setColorAt(0, QColor(170, 20, 240, 100)) radialGrad.setColorAt(0.5, QColor(20, 10, 255, 40)) radialGrad.setColorAt(1, QColor(120, 20, 240, 10)) deltoidRadial.setPen(QPen(QColor(170, 20, 240))) deltoidRadial.setBrush(QBrush(radialGrad)) # set some basic customPlot config: customPlot.setInteractions(QCP.iRangeDrag | QCP.iRangeZoom | QCP.iSelectPlottables) customPlot.axisRect().setupFullAxesBox() customPlot.rescaleAxes() customPlot.show() # Create and show the form
def paint(self, painter, option, widget=None): painter.setRenderHint(QPainter.Antialiasing) brush = QBrush(QColor(100, 100, 100, 150)) # QBrush(QColor('#3B9CD9')) painter.setBrush(brush) std_pen = QPen( QColor(30, 43, 48) ) # QColor(30, 43, 48) # used for header title and minimal std dark border std_pen.setWidthF(1.5) # painter.setPen(std_pen) if self.parent_node.design_style == 'extended': if GlobalStorage.storage['design style'] == 'dark std': c = self.parent_node.color # main rect body_gradient = QRadialGradient( self.boundingRect().topLeft(), self.flow.pythagoras(self.height, self.width)) body_gradient.setColorAt( 0, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 200)) body_gradient.setColorAt( 1, QColor(c.red() / 10 + 100, c.green() / 10 + 100, c.blue() / 10 + 100, 0)) painter.setBrush(body_gradient) painter.setPen(Qt.NoPen) painter.drawRoundedRect(self.boundingRect(), 12, 12) header_gradient = QLinearGradient( self.get_header_rect().topRight(), self.get_header_rect().bottomLeft()) header_gradient.setColorAt( 0, QColor(c.red(), c.green(), c.blue(), 255)) header_gradient.setColorAt( 1, QColor(c.red(), c.green(), c.blue(), 0)) painter.setBrush(header_gradient) painter.setPen(Qt.NoPen) painter.drawRoundedRect(self.get_header_rect(), 12, 12) elif GlobalStorage.storage['design style'] == 'dark tron': # main rect c = QColor('#212224') painter.setBrush(c) pen = QPen(self.parent_node.color) pen.setWidth(2) painter.setPen(pen) body_path = self.get_extended_body_path_TRON_DESIGN(10) painter.drawPath(body_path) # painter.drawRoundedRect(self.boundingRect(), 12, 12) c = self.parent_node.color header_gradient = QLinearGradient( self.get_header_rect().topRight(), self.get_header_rect().bottomLeft()) header_gradient.setColorAt( 0, QColor(c.red(), c.green(), c.blue(), 255)) header_gradient.setColorAt( 0.5, QColor(c.red(), c.green(), c.blue(), 100)) header_gradient.setColorAt( 1, QColor(c.red(), c.green(), c.blue(), 0)) painter.setBrush(header_gradient) header_path = self.get_extended_header_path_TRON_DESIGN(10) painter.drawPath(header_path) painter.setFont(self.display_name_font) painter.setPen(std_pen) painter.drawText(self.get_title_rect(), Qt.AlignVCenter | Qt.AlignLeft, self.parent_node.title) painter.setBrush(Qt.NoBrush) painter.setPen(QPen(Qt.white, 1)) # painter.drawRect(self.get_header_rect()) elif self.parent_node.design_style == 'minimalistic': path = QPainterPath() path.moveTo(-self.width / 2, 0) if GlobalStorage.storage['design style'] == 'dark std': path.cubicTo(-self.width / 2, -self.height / 2, -self.width / 2, -self.height / 2, 0, -self.height / 2) path.cubicTo(+self.width / 2, -self.height / 2, +self.width / 2, -self.height / 2, +self.width / 2, 0) path.cubicTo(+self.width / 2, +self.height / 2, +self.width / 2, +self.height / 2, 0, +self.height / 2) path.cubicTo(-self.width / 2, +self.height / 2, -self.width / 2, +self.height / 2, -self.width / 2, 0) path.closeSubpath() c = self.parent_node.color body_gradient = QLinearGradient( self.boundingRect().bottomLeft(), self.boundingRect().topRight()) # 2*self.flow.pythagoras(self.height, self.width)) body_gradient.setColorAt( 0, QColor(c.red(), c.green(), c.blue(), 150)) body_gradient.setColorAt( 1, QColor(c.red(), c.green(), c.blue(), 80)) painter.setBrush(body_gradient) painter.setPen(std_pen) elif GlobalStorage.storage['design style'] == 'dark tron': corner_size = 10 path.lineTo(-self.width / 2 + corner_size / 2, -self.height / 2 + corner_size / 2) path.lineTo(0, -self.height / 2) path.lineTo(+self.width / 2 - corner_size / 2, -self.height / 2 + corner_size / 2) path.lineTo(+self.width / 2, 0) path.lineTo(+self.width / 2 - corner_size / 2, +self.height / 2 - corner_size / 2) path.lineTo(0, +self.height / 2) path.lineTo(-self.width / 2 + corner_size / 2, +self.height / 2 - corner_size / 2) path.closeSubpath() c = QColor('#36383B') painter.setBrush(c) pen = QPen(self.parent_node.color) pen.setWidth(2) painter.setPen(pen) painter.drawPath(path) painter.setFont(self.display_name_font) painter.drawText(self.boundingRect(), Qt.AlignCenter, self.parent_node.title)
def drawForeground(self, painter, rect): """Draws all connections and borders around selected items.""" # DRAW CONNECTIONS for ni in self.all_node_instances: for o in ni.outputs: for cpi in o.connected_port_instances: path = self.connection_path( o.gate.get_scene_center_pos(), cpi.gate.get_scene_center_pos()) w = path.boundingRect().width() h = path.boundingRect().height() gradient = QRadialGradient(path.boundingRect().center(), pythagoras(w, h) / 2) pen = Design.flow_theme.get_flow_conn_pen_inst(o.type_) c = pen.color() # highlight hovered connections if self.hovered_port_inst_gate == o.gate or self.hovered_port_inst_gate is cpi.gate: c = QColor('#c5c5c5') pen.setWidth(5) c_r = c.red() c_g = c.green() c_b = c.blue() gradient.setColorAt(0.0, QColor(c_r, c_g, c_b, 255)) gradient.setColorAt(0.75, QColor(c_r, c_g, c_b, 200)) gradient.setColorAt(0.95, QColor(c_r, c_g, c_b, 0)) gradient.setColorAt(1.0, QColor(c_r, c_g, c_b, 0)) pen.setBrush(gradient) painter.setPen(pen) painter.drawPath(path) # DRAW CURRENTLY DRAGGED CONNECTION if self.dragging_connection: pen = QPen('#101520') pen.setWidth(3) pen.setStyle(Qt.DotLine) painter.setPen(pen) gate_pos = self.gate_selected.get_scene_center_pos() if self.gate_selected.parent_port_instance.direction == 'output': painter.drawPath( self.connection_path(gate_pos, self.last_mouse_move_pos)) else: painter.drawPath( self.connection_path(self.last_mouse_move_pos, gate_pos)) # DRAW SELECTED NIs BORDER for ni in self.selected_node_instances(): pen = QPen(QColor('#245d75')) pen.setWidth(3) painter.setPen(pen) painter.setBrush(Qt.NoBrush) size_factor = 1.2 x = ni.pos().x() - ni.boundingRect().width() / 2 * size_factor y = ni.pos().y() - ni.boundingRect().height() / 2 * size_factor w = ni.boundingRect().width() * size_factor h = ni.boundingRect().height() * size_factor painter.drawRoundedRect(x, y, w, h, 10, 10) # DRAW SELECTED DRAWINGS BORDER for p_o in self.selected_drawings(): pen = QPen(QColor('#a3cc3b')) pen.setWidth(2) painter.setPen(pen) painter.setBrush(Qt.NoBrush) size_factor = 1.05 x = p_o.pos().x() - p_o.width / 2 * size_factor y = p_o.pos().y() - p_o.height / 2 * size_factor w = p_o.width * size_factor h = p_o.height * size_factor painter.drawRoundedRect(x, y, w, h, 6, 6) painter.drawEllipse(p_o.pos().x(), p_o.pos().y(), 2, 2)
def testAllInt(self): grad = QRadialGradient(1, 2, 5, 3, 4) self._assertValues(grad)
def testQPointF(self): grad = QRadialGradient(QPointF(1, 2), 5, QPointF(3, 4)) self._assertValues(grad)
def setup(self): "sets bounds on value arc and color wheel" # bounding boxes self.winBox = QRectF(self.rect()) self.vIoBox = QRectF() # value indicator arc outer self.vIdBox = QRectF() # value indicator box self.vAoBox = QRectF() # value arc outer self.vAiBox = QRectF() # value arc inner self.cWhBox = QRectF() # color wheel self.vIdBox.setSize(QSizeF(15, 15)) self.vIoBox.setSize(self.winBox.size()) self.vAoBox.setSize(self.winBox.size() - self.vIdBox.size() / 2.0) self.vAiBox.setSize(self.vAoBox.size() - QSizeF(20, 20)) self.cWhBox.setSize(self.vAiBox.size() - QSizeF(20, 20)) # center - shifted to the right slightly x = self.winBox.width() - (self.vIdBox.width() + self.vAiBox.width()) / 2.0 self.cen = QPointF(x, self.winBox.height() / 2.0) # positions and initial settings self.vAoBox.moveCenter(self.cen) self.vAiBox.moveCenter(self.cen) self.cWhBox.moveCenter(self.cen) self.vIdBox.moveCenter(self.vIdCen) self.cW_rad = self.cWhBox.width() / 2.0 self.ang_w = radians(self.s_ang) - radians(self.e_ang) # gradients colWhl = QConicalGradient(self.cen, self.o_ang) whl_cols = [ Qt.red, Qt.magenta, Qt.blue, Qt.cyan, Qt.green, Qt.yellow, Qt.red ] for i, c in enumerate(whl_cols[::self.rot_d]): colWhl.setColorAt(i / 6.0, c) rad = min(self.cWhBox.width() / 2.0, self.cWhBox.height() / 2.0) cWhlFade = QRadialGradient(self.cen, rad, self.cen) cWhlFade.setColorAt(0, Qt.white) cWhlFade.setColorAt(1, QColor(255, 255, 255, 0)) self.cWhlBrush1 = QBrush(colWhl) self.cWhlBrush2 = QBrush(cWhlFade) # painter paths (arcs, wheel) rad = self.vAoBox.width() / 2.0 x, y = rad * cos(radians(self.s_ang)), -rad * sin(radians(self.s_ang)) x += self.cen.x() y += self.cen.y() self.vArcPath = QPainterPath(QPointF(x, y)) # value arc (for color) self.vArcPath.arcTo(self.vAoBox, self.s_ang, self.e_ang - self.s_ang) self.vArcPath.arcTo(self.vAiBox, self.e_ang, self.s_ang - self.e_ang) self.vArcPath.closeSubpath() self.vInArcPath = QPainterPath(QPointF(x, y)) # value arc (for mouse) self.vInArcPath.arcTo(self.vIoBox, self.s_ang, self.e_ang - self.s_ang) self.vInArcPath.arcTo(self.vAiBox, self.e_ang, self.s_ang - self.e_ang) self.vInArcPath.closeSubpath() self.colWhlPath = QPainterPath() self.colWhlPath.addEllipse(self.cWhBox)
def paintEvent(self, event: QPaintEvent) -> None: painter: QPainter = QPainter(self) painter.setRenderHints(QPainter.Antialiasing) sw: int = 336 sh: int = 336 scaleX: float = self.width() * 1.0 / sw scaleY: float = self.height() * 1.0 / sh painter.scale(scaleX, scaleY) painter.setPen(Qt.NoPen) painter.fillRect(0, 0, sw, sh, self.__bgColor) iw: float = sw / 7.0 ih: float = sh / 7.0 # mask globalpoint: QPointF = self.mapFromGlobal(QCursor.pos()) point: QPointF = QPointF(globalpoint.x() / scaleX, globalpoint.y() / scaleY) # 绘制光晕背景 if self.underMouse(): effectradius: int = 58 painter.setCompositionMode(QPainter.CompositionMode_DestinationIn) radialGrad: QRadialGradient = QRadialGradient(point, effectradius) radialGrad.setColorAt(0, QColor(0, 0, 0, 120)) radialGrad.setColorAt(1, QColor(0, 0, 0, 255)) painter.setBrush(radialGrad) painter.drawEllipse(point, effectradius, effectradius) painter.setCompositionMode( QPainter.CompositionMode_DestinationOver) painter.setBrush(Qt.NoBrush) for row in range(6): for column in range(7): rect: QRectF = QRectF(column * iw, (row + 1) * ih, iw, ih).adjusted(3, 3, -3, -3) if rect.contains(point): painter.save() painter.setCompositionMode( QPainter.CompositionMode_SourceOver) painter.setPen(QPen(QColor(220, 220, 220, 160), 2)) painter.drawRoundedRect(rect, 2, 2) painter.restore() continue else: painter.setPen(QPen(self.__shadowColor, 2)) painter.drawRoundedRect(rect, 2, 2) # 绘制圆形的光晕底层背景 painter.fillRect(0, 0, sw, sh, QColor(200, 200, 200, 50)) # 绘制头部中文数字,先设置图像叠加模式为源在上面 painter.setCompositionMode(QPainter.CompositionMode_SourceOver) painter.setPen(self.__textColor) listHead: List[AnyStr] = ["一", "二", "三", "四", "五", "六", "日"] for i in range(7): painter.drawText(i * iw, 0, iw, ih, Qt.AlignCenter, listHead[i]) # 绘制日期 for row in range(6): for column in range(7): if self.__dateItem[row][column].day > 0: rect: QRectF = QRectF(column * iw, (row + 1) * ih, iw, ih).adjusted(3, 3, -3, -3) # 如果是选中的日期则突出绘制背景 if QDate.currentDate() == QDate( self.__dateItem[row][column].year, self.__dateItem[row][column].month, self.__dateItem[row][column].day): painter.setPen(QPen(self.__selectColor, 2)) painter.setBrush(Qt.NoBrush) # 如果和光晕效果重叠则边框高亮 if rect.contains(point): painter.setPen( QPen(self.__selectColor.lighter(), 2)) # 绘制圆角边框 painter.drawRoundedRect(rect, 2, 2) # 绘制里边背景 painter.setPen(Qt.NoPen) painter.setBrush(self.__selectColor) painter.drawRoundedRect(rect.adjusted(4, 4, -4, -4), 2, 2) painter.setPen(self.__textColor) painter.drawText(rect, Qt.AlignCenter, str(self.__dateItem[row][column].day))