Пример #1
0
 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)
Пример #2
0
    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()
Пример #3
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())
Пример #4
0
    def __draw03_gradient(self):  #在窗口上绘图
        painter = QPainter(self)
        ##      painter.setRenderHint(QPainter.Antialiasing)
        ##      painter.setRenderHint(QPainter.TextAntialiasing)

        #设置画笔
        pen = QPen()
        ##      pen.setWidth(2)   #线宽
        ##      pen.setColor(Qt.red)   #划线颜色
        pen.setStyle(Qt.NoPen)  #线的类型,实线、虚线等

        painter.setPen(pen)

        W = self.width()  #绘图区宽度
        H = self.height()  #绘图区高度

        ##      radialGrad=QRadialGradient(W/4,H/2,W/10,W/5,H/2)
        ##      radialGrad=QRadialGradient(W/2,H/2,W/2,3*W/4,H/2)    #原点就是焦点
        radialGrad = QRadialGradient(W / 2, H / 2, W / 8, W / 2, H / 2)
        radialGrad.setColorAt(0, Qt.yellow)  #yellow
        radialGrad.setColorAt(1, Qt.blue)  #green
        ## PadSpread,  RepeatSpread,  ReflectSpread
        radialGrad.setSpread(QGradient.ReflectSpread)
        painter.setBrush(radialGrad)

        ##      rect=QRect(W/4,H/4,W/2,H/2)

        ####      linearGrad=QLinearGradient(rect.left(), rect.top(), rect.right(), rect.top())#从左到右
        ##      linearGrad=QLinearGradient(rect.left(), rect.top(), rect.right(), rect.bottom())#从左到右
        ##
        ##      linearGrad.setColorAt(0,Qt.blue) #起点颜色
        ##      linearGrad.setColorAt(0.5,Qt.white)    #中间点颜色
        ##      linearGrad.setColorAt(1,Qt.blue)     #终点颜色
        ##   ##      linearGrad.setSpread(QGradient.ReflectSpread)   #展布模式
        ##      painter.setBrush(linearGrad)

        ##      coniGrad=QConicalGradient(W/2, H/2, 0)
        ##      coniGrad.setColorAt(0,     Qt.yellow)
        ##      coniGrad.setColorAt(0.5,   Qt.blue)
        ##      coniGrad.setColorAt(1,     Qt.green)  #green
        ##      painter.setBrush(coniGrad)

        painter.drawRect(self.rect())  #填充整个窗口
Пример #5
0
    def drawTemperature(self, painter):

        if self.value >= self.critical:
            color = QColor(255, 0, 0)

        elif self.value >= self.normal:
            color = QColor(0, 200, 0)

        else:
            color = QColor(0, 0, 255)

        scale = QLinearGradient(0, 0, 5, 0)
        bulb = QRadialGradient(0, 267.0, 10, -5, 262)

        scale.setSpread(QGradient.ReflectSpread)
        bulb.setSpread(QGradient.ReflectSpread)

        color.setHsv(color.hue(), color.saturation(), color.value())
        scale.setColorAt(1, color)
        bulb.setColorAt(1, color)

        color.setHsv(color.hue(), color.saturation() - 200, color.value())
        scale.setColorAt(0, color)
        bulb.setColorAt(0, color)

        factor = self.value - self.m_min
        factor = (factor / self.m_max) - self.m_min

        temp = SCALE_HEIGHT * factor
        height = temp + OFFSET

        painter.setPen(Qt.NoPen)
        painter.setBrush(scale)
        painter.drawRect(-5, 252 + OFFSET - height, 10, height)
        painter.setBrush(bulb)
        rect = QRectF(-10, 258, 20, 20)
        painter.drawEllipse(rect)