Exemple #1
0
 def draw_pieces():
     """draw pieces"""
     # black pieces
     qp.setPen(QPen(QColor(0, 0, 0), 1, Qt.SolidLine))
     for x in range(15):
         for y in range(15):
             if self.g.g_map[x][y] == 1:
                 if self.flash_cnt % 2 == 1 and (
                         x, y) in self.flash_pieces:
                     continue
                 radial = QRadialGradient(40 * (x + 1), 40 * (y + 1),
                                          15, 40 * x + 35, 40 * y + 35)
                 radial.setColorAt(0, QColor(96, 96, 96))
                 radial.setColorAt(1, QColor(0, 0, 0))
                 qp.setBrush(QBrush(radial))
                 qp.drawEllipse(QPoint(40 * (x + 1), 40 * (y + 1)), 15,
                                15)
     # white pieces
     qp.setPen(QPen(QColor(255, 255, 255), 1, Qt.SolidLine))
     for x in range(15):
         for y in range(15):
             if self.g.g_map[x][y] == 2:
                 if self.flash_cnt % 2 == 1 and (
                         x, y) in self.flash_pieces:
                     continue
                 radial = QRadialGradient(40 * (x + 1), 40 * (y + 1),
                                          15, 40 * x + 35, 40 * y + 35)
                 radial.setColorAt(0, QColor(255, 255, 255))
                 radial.setColorAt(1, QColor(160, 160, 160))
                 qp.setBrush(QBrush(radial))
                 qp.drawEllipse(QPoint(40 * (x + 1), 40 * (y + 1)), 15,
                                15)
Exemple #2
0
 def draw_pieces():
     #             """绘制棋子"""
     #             # 绘制黑棋子
     qp.setPen(QPen(QColor(0, 0, 0), 1, Qt.SolidLine))
     # qp.setBrush(QColor(0, 0, 0))
     for x in range(self.H):
         for y in range(self.W):
             if self.g.chessboard[x, y] == 1:
                 #                        if self.flash_cnt % 2 == 1 and (x, y) in self.flash_pieces:
                 #                             continue
                 radial = QRadialGradient(40 * (x + 1), 40 * (y + 1),
                                          15, 40 * x + 35,
                                          40 * y + 35)  # 棋子的渐变效果
                 radial.setColorAt(0, QColor(96, 96, 96))
                 radial.setColorAt(1, QColor(0, 0, 0))
                 qp.setBrush(QBrush(radial))
                 qp.drawEllipse(QPoint(40 * (x + 1), 40 * (y + 1)), 15,
                                15)
     #             # 绘制白棋子
     qp.setPen(QPen(QColor(160, 160, 160), 1, Qt.SolidLine))
     # qp.setBrush(QColor(255, 255, 255))
     for x in range(self.H):
         for y in range(self.W):
             if self.g.chessboard[x, y] == 2:
                 #                         if self.flash_cnt % 2 == 1 and (x, y) in self.flash_pieces:
                 #                             continue
                 radial = QRadialGradient(40 * (x + 1), 40 * (y + 1),
                                          15, 40 * x + 35,
                                          40 * y + 35)  # 棋子的渐变效果
                 radial.setColorAt(0, QColor(255, 255, 255))
                 radial.setColorAt(1, QColor(160, 160, 160))
                 qp.setBrush(QBrush(radial))
                 qp.drawEllipse(QPoint(40 * (x + 1), 40 * (y + 1)), 15,
                                15)
Exemple #3
0
    def paintEvent(self, event):
        super().paintEvent(event)

        painter = QPainter(self)

        size = self.size()
        brush = QBrush()

        smallest_dim = size.width()
        if smallest_dim > size.height():
            smallest_dim = size.height()

        smallest_dim = smallest_dim / 2
        smallest_dim -= 2

        center_x = size.width() / 2
        center_y = size.height() / 2
        centerpoint = QPoint(center_x, center_y)

        radius = smallest_dim

        painter.setPen(QPen(QColor('lightgray'), 0))
        brush.setStyle(Qtc.SolidPattern)

        radial = QRadialGradient(center_x, center_y / 2, radius)
        radial.setColorAt(0, Qtc.white)
        radial.setColorAt(0.8, Qtc.darkGray)
        painter.setBrush(QBrush(radial))
        painter.drawEllipse(centerpoint, radius, radius)

        # Draw the colored center
        radial = QRadialGradient(center_x, center_y / 2, radius)
        radial.setColorAt(0, Qtc.white)

        if self.curState:
            radial.setColorAt(.7, self.on_color)
            brush.setColor(self.on_color)
            painter.setPen(QPen(self.on_color, 0))
        else:
            radial.setColorAt(.7, self.off_color)
            brush.setColor(self.off_color)
            painter.setPen(QPen(self.off_color, 0))

        brush.setStyle(Qtc.SolidPattern)
        painter.setBrush(QBrush(radial))
        if smallest_dim <= 30:
            radius = radius - 3
        elif smallest_dim <= 60:
            radius = radius - 4
        elif smallest_dim <= 100:
            radius = radius - 5
        elif smallest_dim <= 200:
            radius = radius - 6
        elif smallest_dim <= 300:
            radius = radius - 7
        else:
            radius = radius - 9
        painter.drawEllipse(centerpoint, radius, radius)
    def drawGradients(self, painter: QPainter):
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        gr1 = QRadialGradient(20.0, 20.0, 110.0)
        painter.setBrush(gr1)
        painter.drawEllipse(20.0, 20.0, 100.0, 100.0)

        gr2 = QRadialGradient(190.0, 70.0, 50.0, 190.0, 70.0)
        gr2.setColorAt(0.2, Qt.yellow)
        gr2.setColorAt(0.7, Qt.black)
        painter.setBrush(gr2)
        painter.drawEllipse(140.0, 20.0, 100.0, 100.0)
Exemple #5
0
    def paintEvent(self, event):
        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()
Exemple #6
0
def gradient_darker(grad, factor):
    """Return a copy of the QGradient darkened by factor.

    .. note:: Only QLinearGradeint and QRadialGradient are supported.

    """
    if type(grad) is QGradient:
        if grad.type() == QGradient.LinearGradient:
            grad = sip.cast(grad, QLinearGradient)
        elif grad.type() == QGradient.RadialGradient:
            grad = sip.cast(grad, QRadialGradient)

    if isinstance(grad, QLinearGradient):
        new_grad = QLinearGradient(grad.start(), grad.finalStop())
    elif isinstance(grad, QRadialGradient):
        new_grad = QRadialGradient(grad.center(), grad.radius(),
                                   grad.focalPoint())
    else:
        raise TypeError

    new_grad.setCoordinateMode(grad.coordinateMode())

    for pos, color in grad.stops():
        new_grad.setColorAt(pos, color.darker(factor))

    return new_grad
 def paintEvent(self, QPaintEvent):
     p = QPainter(self)
     r = self.rect()
     p.setPen(self.pen)
     if (self.sd.style == QGradient.LinearGradient):
         linearGradient = QLinearGradient(self.startPoint, self.endPoint)
         linearGradient.setColorAt(0.0, self.sd.startColor)
         linearGradient.setColorAt(1.0, self.sd.endColor)
         linearGradient.setSpread(self.sd.spread)
         p.setBrush(linearGradient)
     elif (self.sd.style == QGradient.RadialGradient):
         rr = math.sqrt(
             math.pow(self.endPoint.x() - self.startPoint.x(), 2) + math.pow(self.endPoint.y() - self.startPoint.y(),
                                                                             2))
         radialGradient = QRadialGradient(self.startPoint, rr, self.startPoint)
         radialGradient.setColorAt(0.0, self.sd.startColor)
         radialGradient.setColorAt(1.0, self.sd.endColor)
         radialGradient.setSpread(self.sd.spread)
         p.setBrush(radialGradient)
     elif (self.sd.style == QGradient.ConicalGradient):
         angle = math.atan2(self.endPoint.y() - self.startPoint.y(), self.endPoint.x() - self.startPoint.x())
         conicalGradient = QConicalGradient(self.startPoint, -(180 * angle) / math.pi)
         conicalGradient.setColorAt(0.0, self.sd.startColor)
         conicalGradient.setColorAt(1.0, self.sd.endColor)
         p.setBrush(conicalGradient)
         p.drawRect(r)
Exemple #8
0
    def paintEvent(self, event):

        background = QRadialGradient(QPointF(self.rect().topLeft()), 500,
                                     QPointF(self.rect().bottomRight()))
        background.setColorAt(0, self.backgroundColor1)
        background.setColorAt(1, self.backgroundColor2)

        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(event.rect(), QBrush(background))

        painter.setPen(self.pen)

        for bubble in self.bubbles:

            if QRectF(bubble.position - QPointF(bubble.radius, bubble.radius),
                      QSizeF(2 * bubble.radius, 2 * bubble.radius)).intersects(
                          QRectF(event.rect())):
                bubble.drawBubble(painter)

        if self.newBubble:

            self.newBubble.drawBubble(painter)

        painter.end()
    def drawTarget(self):
        if self.target == None:
            return

        x = self.target.x
        y = self.target.y
        width = self.target.width
        height = self.target.height

        # prepare drawing
        painter = QPainter(self.targetPixmap)

        if self.target.visualForm == 'red_dot' or self.target.visualForm == 'dot+head':
            radialGrad = QRadialGradient(QPoint(x, y), max(width, height) / 2)
            radialGrad.setColorAt(0, self.target.color)
            radialGrad.setColorAt(1, Qt.white)

            targetBrush = QBrush(radialGrad)
            targetPen = QPen(Qt.transparent, 0, Qt.SolidLine)
            painter.setPen(targetPen)

            painter.setBrush(targetBrush)
            painter.drawEllipse(x - width / 2, y - height / 2, width, height)

        if self.target.visualForm == 'nao_head' or self.target.visualForm == 'dot+head':
            painter.drawPixmap(x - NAO_HEAD_SIZE / 2, y - NAO_HEAD_SIZE / 2,
                               self.naoPixmap)

        painter.end()

        self.viewport().update()
Exemple #10
0
    def paint(self, painter, option, widget):

        if self.is_node1:
            color = Qt.green
            dark_color = Qt.darkGreen
        else:
            color = Qt.yellow
            dark_color = Qt.darkYellow

        gradient = QRadialGradient(-3, -3, 10)
        if option.state & QStyle.State_MouseOver:
            gradient.setCenter(3, 3)
            gradient.setFocalPoint(3, 3)
            gradient.setColorAt(1, QColor(color).lighter(120))
            gradient.setColorAt(0, QColor(dark_color).lighter(120))
        else:
            gradient.setColorAt(0, color)
            gradient.setColorAt(1, dark_color)

        painter.setBrush(QBrush(gradient))
        painter.setPen(QPen(Qt.black, 0))
        painter.drawEllipse(-10, -10, 20, 20)

        # node text
        painter.setPen(QPen(QColor(Qt.black), 0))
        painter.drawText(13, 4, "%s" % self.node_record.index)
    def paintEvent(self, evt):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setPen(QPen(Qt.black, 1))

        realSize = min(self.width(), self.height())  # 窗口的短边
        painter.translate(self.width() / 2.0, self.height() / 2.0)  # 原点平移到窗口中心
        painter.scale(realSize / self.scaledSize, realSize / self.scaledSize)  # 缩放,窗口的短边值映射为self.scaledSize
        gradient = QRadialGradient(QPointF(0, 0), self.scaledSize / 2.0, QPointF(0, 0))  # 辐射渐变

        # 画边框外圈和内圈
        for color, radius in [(self.colorBorderOut, self.radiusBorderOut),  # 边框外圈
                              (self.colorBorderIn, self.radiusBorderIn)]:  # 边框内圈
            gradient.setColorAt(1, color)
            painter.setBrush(QBrush(gradient))
            painter.drawEllipse(QPointF(0, 0), radius, radius)

        # 画内圆
        if self.state == 'off':
            gradient.setColorAt(0, self.colorOffBegin)
            gradient.setColorAt(1, self.colorOffEnd)
        else:
            gradient.setColorAt(0, self.colorOnBegin)
            gradient.setColorAt(1, self.colorOnEnd)

        painter.setBrush(QBrush(gradient))
        painter.drawEllipse(QPointF(0, 0), self.radiusCircle, self.radiusCircle)
Exemple #12
0
 def __init__(self, index, name, func, parent):
     super().__init__(parent)
     self.index = index
     self.name = name
     self.function = func
     self.resize(TILE_WIDTH << 2, TILE_HEIGHT << 2)
     self.show()
     self.opacity = None
     self.setMouseTracking(True)
     self.color = QColor(50 * self.index, 255, 255 - 10 * self.index)
     self.gradient = QRadialGradient(
         50 + 10 * self.index, 50 - 10 * self.index, 500 - 50 * self.index,
         50 + 10 * self.index, 100 - 10 * self.index)
     self.gradient.setColorAt(0, QColor(200, 200, 200))
     self.gradient.setColorAt(0.5, QColor(50 * self.index, 255, 255 - 10 * self.index))
     self.gradient.setColorAt(1, QColor(200, 200, 200))
     self.brush = QBrush(self.gradient)
     self.path = QPainterPath()
     rect = QRectF(TILE_WIDTH * 1.5, TILE_HEIGHT * 1.5, TILE_WIDTH * 1.5, TILE_HEIGHT * 1.5)
     total = self.parent().total - 1
     if total < 3:
         total = 3
     if self.index == 0:
         self.path.arcMoveTo(rect, 90)
         self.path.arcTo(rect, 90, 360)
     else:
         self.path.arcMoveTo(QRectF(self.rect()), 90 + self.index * 360 // total)
         self.path.arcTo(QRectF(self.rect()), 90 + self.index * 360 // total,  360 // total)
         self.path.arcTo(rect, 90 + self.index * 360 // total + 360 // total, -360 // total)
         self.path.arcTo(QRectF(self.rect()), 90 + self.index * 360 // total,  0)
Exemple #13
0
    def updateBrush(self):
        gradient = QRadialGradient(QPointF(self.radius, self.radius), self.radius, QPointF(self.radius*0.5, self.radius*0.5))

        gradient.setColorAt(0, QColor(255, 255, 255, 255))
        gradient.setColorAt(0.25, self.innerColor)
        gradient.setColorAt(1, self.outerColor)
        self.brush = QBrush(gradient)
Exemple #14
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))
Exemple #15
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))
Exemple #16
0
    def __paintRound(self):
        """
        Private method to paint a round raised LED.
        """
        # Initialize coordinates, width and height of the LED
        width = self.__getBestRoundSize()

        # Calculate the gradient for the LED
        wh = width / 2
        color = self.__led_on and self.__led_color or self.__offcolor
        gradient = QRadialGradient(wh, wh, wh, 0.8 * wh, 0.8 * wh)
        gradient.setColorAt(0.0, color.lighter(200))
        gradient.setColorAt(0.6, color)
        if self.__framedLed:
            gradient.setColorAt(0.9, color.darker())
            gradient.setColorAt(1.0, self.palette().color(QPalette.Dark))
        else:
            gradient.setColorAt(1.0, color.darker())

        # now do the drawing
        paint = QPainter(self)
        paint.setRenderHint(QPainter.Antialiasing, True)
        paint.setBrush(QBrush(gradient))
        paint.setPen(Qt.NoPen)
        paint.drawEllipse(1, 1, width, width)
        paint.end()
Exemple #17
0
    def setupParametricCurveDemo(self):
        self.demoName = "Parametric Curves Demo"

        # create empty curve objects. As they are not adopted by main QCustomPlot an explicit
        # reference must be kept
        self.fermatSpiral1 = QCustomPlot.QCPCurve(self.customPlot.xAxis,
                                                  self.customPlot.yAxis)
        self.fermatSpiral2 = QCustomPlot.QCPCurve(self.customPlot.xAxis,
                                                  self.customPlot.yAxis)
        self.deltoidRadial = QCustomPlot.QCPCurve(self.customPlot.xAxis,
                                                  self.customPlot.yAxis)
        # generate the curve data points:
        pointCount = 501
        dataSpiral1 = [[0.0] * pointCount, [0.0] * pointCount,
                       [0.0] * pointCount]
        dataSpiral2 = [[0.0] * pointCount, [0.0] * pointCount,
                       [0.0] * pointCount]
        dataDeltoid = [[0.0] * pointCount, [0.0] * pointCount,
                       [0.0] * pointCount]
        for i in range(0, pointCount):
            phi = i / (pointCount - 1) * 8 * math.pi
            theta = i / (pointCount - 1) * 2 * math.pi
            dataSpiral1[0][i] = float(i)
            dataSpiral1[1][i] = math.sqrt(phi) * math.cos(phi)
            dataSpiral1[2][i] = math.sqrt(phi) * math.sin(phi)
            dataSpiral2[0][i] = float(i)
            dataSpiral2[1][i] = -dataSpiral1[1][i]
            dataSpiral2[2][i] = -dataSpiral1[2][i]
            dataDeltoid[0][i] = float(i)
            dataDeltoid[1][i] = 2 * math.cos(2 * theta) + math.cos(
                1 * theta) + 2 * math.sin(theta)
            dataDeltoid[2][i] = 2 * math.sin(2 * theta) - math.sin(1 * theta)

        # pass the data to the curves; we know t (i in loop above) is ascending, so set alreadySorted=true (saves an extra internal sort):
        self.fermatSpiral1.setData(dataSpiral1[0], dataSpiral1[1],
                                   dataSpiral1[2], True)
        self.fermatSpiral2.setData(dataSpiral2[0], dataSpiral2[1],
                                   dataSpiral2[2], True)
        self.deltoidRadial.setData(dataDeltoid[0], dataDeltoid[1],
                                   dataDeltoid[2], True)
        # color the curves:
        self.fermatSpiral1.setPen(QPen(Qt.blue))
        self.fermatSpiral1.setBrush(QBrush(QColor(0, 0, 255, 20)))
        self.fermatSpiral2.setPen(QPen(QColor(255, 120, 0)))
        self.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))
        self.deltoidRadial.setPen(QPen(QColor(170, 20, 240)))
        self.deltoidRadial.setBrush(QBrush(radialGrad))
        # set some basic customPlot config:
        self.customPlot.setInteractions(
            QCustomPlot.QCP.Interactions(QCustomPlot.QCP.iRangeDrag
                                         | QCustomPlot.QCP.iRangeZoom
                                         | QCustomPlot.QCP.iSelectPlottables))
        self.customPlot.axisRect().setupFullAxesBox()
        self.customPlot.rescaleAxes()
 def point_obj(self):
     p = pg.QtGui.QPainter(self.picture)
     p.setRenderHint(QtGui.QPainter.Antialiasing, True)
     gradient = QRadialGradient(QtCore.QPointF(self.x, self.y), 5)
     gradient.setColorAt(0, QColor('#fc030b'))
     gradient.setColorAt(1, QColor('#9065e0'))
     p.setBrush(gradient)
     p.setPen(QtCore.Qt.NoPen)
     p.drawEllipse(QtCore.QPointF(self.x, self.y), 3, 3)
     p.end()
Exemple #19
0
    def drawMagnifierOnVideo(width, height, maskPixmap, dragPos, zoomPixmap, surface, painter, offset):
        ''' Draw Magnifier on Video '''
        dim = min(width, height)
        MAX_MAGNIFIER = 229
        magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3)
        radius = magnifierSize / 2
        ring = radius - 15
        box = QSize(magnifierSize, magnifierSize)

        # reupdate our mask
        if maskPixmap.size() != box:
            maskPixmap = QPixmap(box)
            maskPixmap.fill(Qt.transparent)
            g = QRadialGradient()
            g.setCenter(radius, radius)
            g.setFocalPoint(radius, radius)
            g.setRadius(radius)
            g.setColorAt(1.0, QColor(64, 64, 64, 0))
            g.setColorAt(0.5, QColor(0, 0, 0, 255))
            mask = QPainter(maskPixmap)
            mask.setRenderHint(QPainter.HighQualityAntialiasing)
            mask.setCompositionMode(QPainter.CompositionMode_Source)
            mask.setBrush(g)
            mask.setPen(Qt.NoPen)
            mask.drawRect(maskPixmap.rect())
            mask.setBrush(QColor(Qt.transparent))
            mask.drawEllipse(g.center(), ring, ring)
            mask.end()

        center = 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 zoomPixmap.size() != box:
            zoomPixmap = QPixmap(box)
            zoomPixmap.fill(Qt.lightGray)

        if True:
            painter_p = QPainter(zoomPixmap)
            painter_p.translate(-xy)
            largePixmap = QPixmap.fromImage(surface.image)
            painter_p.drawPixmap(offset, largePixmap)
            painter_p.end()

        clipPath = QPainterPath()
        clipPath.addEllipse(QPointF(center), ring, ring)
        painter.setClipPath(clipPath)
        painter.drawPixmap(corner, zoomPixmap)
        painter.setClipping(False)
        painter.drawPixmap(corner, maskPixmap)
        painter.setPen(Qt.gray)
        painter.drawPath(clipPath)
        return
 def paint(self, painter, option, widget):
     ellipse = self.boundingRect()
     gradient = QRadialGradient(0, 8, 20, 0, 8)
     gradient.setColorAt(0.0, Qt.white)
     gradient.setColorAt(0.8, self.color)
     painter.setBrush(gradient)
     painter.setPen(self.color)
     painter.drawEllipse(ellipse)
     painter.setFont(QFont("Verdana", 8))
     painter.setPen(QColor(Qt.white))
     painter.drawText(ellipse, Qt.AlignCenter, self.name)
Exemple #21
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setPen(QPen(Qt.black, 4, Qt.SolidLine))

        radialGradient = QRadialGradient(QPoint(100, 100), 100)
        radialGradient.setColorAt(0.0, Qt.red)
        radialGradient.setColorAt(0.8, Qt.green)
        radialGradient.setColorAt(1.0, Qt.yellow)

        painter.setBrush(QBrush(radialGradient))
        painter.drawRect(10, 10, 200, 200)
Exemple #22
0
 def paint(self, painter, option, widget):
     gradient = QRadialGradient(-3, -3, 10)
     if option.state & QStyle.State_Sunken:
         gradient.setCenter(3, 3)
         gradient.setFocalPoint(3, 3)
         gradient.setColorAt(0, QColor(Qt.yellow).light(120))
     else:
         gradient.setColorAt(0, QColor(Qt.yellow).light(120))
     painter.setBrush(gradient)
     painter.setPen(QPen(Qt.black, 0))
     painter.drawRoundedRect(self.boundingRect(), 3, 3)
    def drawBackground(self, painter, widget):

        painter.setRenderHint(QPainter.Antialiasing)
        painter.setPen(Qt.NoPen)

        p1 = QPointF(80, 80)
        g = QRadialGradient(p1 * 0.2, 80 * 1.1)

        g.setColorAt(0.0, widget.palette().light().color())
        g.setColorAt(1.0, widget.palette().dark().color())
        painter.setBrush(g)
        painter.drawEllipse(0, 0, 80, 80)

        p2 = QPointF(40, 40)
        g = QRadialGradient(p2, 70 * 1.3)

        g.setColorAt(0.0, widget.palette().midlight().color())
        g.setColorAt(1.0, widget.palette().dark().color())
        painter.setBrush(g)
        painter.drawEllipse(7.5, 7.5, 65, 65)
Exemple #24
0
 def draw_center(self, qp, event, w):
     w *= 0.2
     rect = QRect()
     rect.setSize(QSize(w, w))
     rect.moveCenter(event.rect().center())
     rad = rect.width() / 2
     cap = QRadialGradient(rect.center(), rad)
     cap.setColorAt(0, Qt.white)
     cap.setColorAt(1, Qt.gray)
     qp.setPen(QPen(Qt.black, 1))
     qp.setBrush(QBrush(cap))
     qp.drawEllipse(rect)
Exemple #25
0
    def __init__(self, nx_node, pos):
        """
        Create node in the graph scene

        :param tuple nx_node: Node info
        :param x_y: Position of the node
        """
        super().__init__(nx_node, pos)

        # color around ellipse
        outline_color = QColor('grey')
        outline_style = Qt.SolidLine
        outline_width = 1
        if self.status_wallet:
            outline_color = QColor('black')
            outline_width = 2
        if not self.status_member:
            outline_color = QColor('red')
            outline_style = Qt.SolidLine
        self.setPen(QPen(outline_color, outline_width, outline_style))

        # text inside ellipse
        self.text_item = QGraphicsSimpleTextItem(self)
        self.text_item.setText(self.text)
        text_color = QColor('grey')
        if self.status_wallet == NodeStatus.HIGHLIGHTED:
            text_color = QColor('black')
        self.text_item.setBrush(QBrush(text_color))
        # center ellipse around text
        self.setRect(0, 0,
                     self.text_item.boundingRect().width() * 2,
                     self.text_item.boundingRect().height() * 2)

        #  set anchor to the center
        self.setTransform(QTransform().translate(
            -self.boundingRect().width() / 2.0,
            -self.boundingRect().height() / 2.0))
        # center text in ellipse
        self.text_item.setPos(self.boundingRect().width() / 4.0,
                              self.boundingRect().height() / 4.0)

        # create gradient inside the ellipse
        gradient = QRadialGradient(
            QPointF(0,
                    self.boundingRect().height() / 4),
            self.boundingRect().width())
        gradient.setColorAt(0, QColor('white'))
        gradient.setColorAt(1, QColor('darkgrey'))
        self.setBrush(QBrush(gradient))

        # cursor change on hover
        self.setAcceptHoverEvents(True)
        self.setZValue(1)
Exemple #26
0
    def gradientCirclePixmap(self):
        """白色带阴影
        """
        xy = self.height() / 2
        radius = self.height() * 0.8

        # 绘制普通状态下圆形的滑块
        circleColor = QRadialGradient(xy, xy, radius, xy, xy)
        circleColor.setColorAt(0.5, QColor(254, 254, 254))
        circleColor.setColorAt(0.7, QColor(0, 0, 0, 60))
        circleColor.setColorAt(0.7, QColor(0, 0, 0, 30))
        circleColor.setColorAt(0.9, QColor(0, 0, 0, 0))
        self._imageCircle = QImage(self.height(), self.height(),
                                   QImage.Format_ARGB32)
        self._imageCircle.fill(Qt.transparent)
        painter = QPainter()
        painter.begin(self._imageCircle)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        painter.setPen(Qt.NoPen)
        painter.setBrush(circleColor)
        painter.drawRoundedRect(0, 0, self.height(), self.height(), xy, xy)
        painter.end()

        # 绘制悬停状态下圆形的滑块
        circleColorHover = QRadialGradient(xy, xy, radius, xy, xy)
        circleColorHover.setColorAt(0.5, QColor(245, 245, 245))
        circleColorHover.setColorAt(0.7, QColor(0, 0, 0, 30))
        circleColorHover.setColorAt(0.9, QColor(0, 0, 0, 0))
        self._imageCircleHover = QImage(self.height(), self.height(),
                                        QImage.Format_ARGB32)
        self._imageCircleHover.fill(Qt.transparent)
        painter = QPainter()
        painter.begin(self._imageCircleHover)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setRenderHint(QPainter.SmoothPixmapTransform, True)
        painter.setPen(Qt.NoPen)
        painter.setBrush(circleColorHover)
        painter.drawRoundedRect(0, 0, self.height(), self.height(), xy, xy)
        painter.end()
    def paintEvent(self, QPaintEvent):
        realSize = min(self.width(), self.height())

        painter = QPainter(self)
        pen = QPen(Qt.black)
        pen.setWidth(1)

        painter.setRenderHint(QPainter.Antialiasing)
        painter.translate(self.width() / 2, self.height() / 2)
        painter.scale(realSize / self.scaledSize, realSize / self.scaledSize)

        gradient = QRadialGradient(QPointF(-500, -500), 1500,
                                   QPointF(-500, -500))
        gradient.setColorAt(0, QColor(224, 224, 224))
        gradient.setColorAt(1, QColor(28, 28, 28))
        painter.setPen(pen)
        painter.setBrush(QBrush(gradient))
        painter.drawEllipse(QPointF(0, 0), 500, 500)

        gradient = QRadialGradient(QPointF(500, 500), 1500, QPointF(500, 500))
        gradient.setColorAt(0, QColor(224, 224, 224))
        gradient.setColorAt(1, QColor(28, 28, 28))
        painter.setPen(pen)
        painter.setBrush(QBrush(gradient))
        painter.drawEllipse(QPointF(0, 0), 450, 450)

        painter.setPen(pen)
        if self.isChecked():
            gradient = QRadialGradient(QPointF(-500, -500), 1500,
                                       QPointF(-500, -500))
            gradient.setColorAt(0, self.on_color_1)
            gradient.setColorAt(1, self.on_color_2)
        else:
            gradient = QRadialGradient(QPointF(500, 500), 1500,
                                       QPointF(500, 500))
            gradient.setColorAt(0, self.off_color_1)
            gradient.setColorAt(1, self.off_color_2)

        painter.setBrush(gradient)
        painter.drawEllipse(QPointF(0, 0), 400, 400)
Exemple #28
0
 def __init__(self, config, type, pulseSound, endingSound):
     super().__init__()
     self.type = type
     self.config = config
     self.width = 200
     self.height = 200
     self.m_boundingRect = QRectF(0, 0, self.width, self.height)
     self.m_painterPath = QPainterPath()
     self.m_painterPath.addEllipse(self.m_boundingRect)
     # radial gradient settings
     self.rgcx = self.m_boundingRect.center().x()
     self.rgcy = self.m_boundingRect.center().y()
     self.rgMinRadius = 50
     self.rgMaxRadius = 300
     self.rgCurrentRadius = 50
     self.rgfx = self.rgcx
     self.rgfy = self.rgcy
     self.rg = QRadialGradient(self.rgcx, self.rgcy, self.rgCurrentRadius, self.rgfx, self.rgfy)
     if self.type is DeusExTypes.POSITIVE:
         firstClr = QColor(Qt.green)
         firstClr.setAlphaF(0.7)
         secondClr = QColor(Qt.darkGreen)
         secondClr.setAlphaF(0.7)
         self.rg.setColorAt(0.0, firstClr)
         self.rg.setColorAt(1.0, secondClr)
     else:
         firstClr = QColor(Qt.red)
         firstClr.setAlphaF(0.7)
         secondClr = QColor(Qt.darkRed)
         secondClr.setAlphaF(0.7)
         self.rg.setColorAt(0.0, firstClr)
         self.rg.setColorAt(1.0, secondClr)
     # pulsing sound
     self.pulseSound = pulseSound
     self.endingSound = endingSound
     # pulsing timer
     self.pulseTimer = QTimer()
     self.pulseTimer.setTimerType(Qt.PreciseTimer)
     self.pulseTimer.timeout.connect(self.pulse)
     self.pulseTimer.start(100)
     # pre activate timer
     self.preActivateTimer = QTimer()
     self.preActivateTimer.setTimerType(Qt.PreciseTimer)
     self.preActivateTimer.timeout.connect(self.preActivate)
     if self.type is DeusExTypes.POSITIVE:
         self.preActivateTimer.start(10000)
     else:
         self.preActivateTimer.start(3000)
     # activate timer
     self.activateTimer = QTimer()
     self.activateTimer.setTimerType(Qt.PreciseTimer)
     self.activateTimer.timeout.connect(self.endingSoundFinished)
    def draw_value(self, painter):

        self.initCoordinateSystem(painter)

        color = QColor(Qt.blue)
        if self.mPointer.value() >= self.mPointer.nominal():
            color = QColor(0, 200, 0)
        if self.mPointer.value() >= self.mPointer.critical():
            color = QColor(Qt.red)

        factor = (self.mPointer.value() - self.mPointer.minimal()) / (
            self.mPointer.maximal() - self.mPointer.minimal())

        painter.setFont(self.mValueFont)
        st = "{} ℃".format(self.mPointer.value())
        Size = painter.fontMetrics().size(Qt.TextSingleLine, st)
        painter.drawText(QPointF(Size.width() / -2, 307 - Size.height()), st)

        slug = QLinearGradient(0.0, 0.0, 5.0, 0.0)
        tank = QRadialGradient(0.0, 267.0, 10.0, -5.0, 262.0)

        slug.setSpread(QGradient.ReflectSpread)
        tank.setSpread(QGradient.ReflectSpread)

        color.setHsv(color.hue(), color.saturation(), color.value())
        slug.setColorAt(1.0, color)
        tank.setColorAt(1.0, color)

        color.setHsv(color.hue(), color.saturation() - 200, color.value())
        slug.setColorAt(0.0, color)
        tank.setColorAt(0.0, color)

        painter.setPen(Qt.NoPen)
        painter.setBrush(slug)

        offset = 10

        temp = 224 * factor

        height = temp + offset

        if 231 < temp:
            height = 231 + offset
        if offset - 5 >= height:
            height = offset - 5

        painter.drawRect(-5, 252 + offset - height, 10, height)

        painter.setBrush(tank)
        painter.drawEllipse(QRectF(-10.0, 257.5, 20.0, 20.0))

        painter.end()
Exemple #30
0
 def paintEvent(self, event):
     painter = QPainter(self)
     pen = QPen()
     pen.setStyle(Qt.NoPen)
     painter.setPen(pen)
     W = self.width()
     H = self.height()
     radialGrad = QRadialGradient(W / 2, H / 2, W / 8, W / 2, H / 2)
     radialGrad.setColorAt(0, Qt.yellow)
     radialGrad.setColorAt(1, Qt.blue)
     radialGrad.setSpread(QGradient.ReflectSpread)
     painter.setBrush(radialGrad)
     painter.drawRect(self.rect())