예제 #1
0
 def paintEvent(self, event):
     """解决继承的QWidget qss无效"""
     super(BallWidget, self).paintEvent(event)
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #2
0
 def paintEvent(self, event):
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     # 反锯齿
     painter.setRenderHint(QPainter.Antialiasing)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #3
0
파일: qled.py 프로젝트: odahoda/noisicaa
    def paintEvent(self, event):
        option=QStyleOption()
        option.initFrom(self)

        h=option.rect.height()
        w=option.rect.width()
        if self.m_shape in (QLed.Triangle, QLed.Round):
            aspect=(4/3.0) if self.m_shape==QLed.Triangle else 2.0
            ah=w/aspect
            aw=w
            if ah>h:
                ah=h
                aw=h*aspect
            x=abs(aw-w)/2.0
            y=abs(ah-h)/2.0
            bounds=QRectF(x,y,aw,ah)
        else:
            size=min(w,h)
            x=abs(size-w)/2.0
            y=abs(size-h)/2.0
            bounds=QRectF(x,y,size,size)

        painter=QPainter(self);
        painter.setRenderHint(QPainter.Antialiasing, True);

        (dark_r,dark_g,dark_b)=self.colours[self.m_onColour if self.m_value else self.m_offColour]

        dark_str="rgb(%d,%d,%d)" % (dark_r,dark_g,dark_b)
        light_str="rgb(%d,%d,%d)" % self.adjust(dark_r,dark_g,dark_b)

        shape = self.shapes[self.m_shape] % (dark_str, light_str)
        shape = shape.encode('utf-8')
        self.renderer.load(QByteArray(shape))
        self.renderer.render(painter, bounds)
def drawIndicatorIcon(palette, style):
    pix = QPixmap(14, 14)
    pix.fill(Qt.transparent)
    branchOption = QStyleOption()
    #r = QRect(QPoint(0, 0), pix.size())
    branchOption.rect = QRect(2, 2, 9, 9) ## ### hardcoded in qcommonstyle.cpp
    branchOption.palette = palette
    branchOption.state = QStyle.State_Children

    p = QPainter()
    ## Draw closed state
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()
    rc = QIcon(pix)
    rc.addPixmap(pix, QIcon.Selected, QIcon.Off)
    ## Draw opened state
    branchOption.state |= QStyle.State_Open
    pix.fill(Qt.transparent)
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()

    rc.addPixmap(pix, QIcon.Normal, QIcon.On)
    rc.addPixmap(pix, QIcon.Selected, QIcon.On)
    return rc
예제 #5
0
    def paintEvent(self, event):
        option = QStyleOption()
        option.initFrom(self)

        h = option.rect.height()
        w = option.rect.width()
        if self.m_shape in (QLed.Triangle, QLed.Round):
            aspect = (4 / 3.0) if self.m_shape == QLed.Triangle else 2.0
            ah = w / aspect
            aw = w
            if ah > h:
                ah = h
                aw = h * aspect
            x = abs(aw - w) / 2.0
            y = abs(ah - h) / 2.0
            bounds = QRectF(x, y, aw, ah)
        else:
            size = min(w, h)
            x = abs(size - w) / 2.0
            y = abs(size - h) / 2.0
            bounds = QRectF(x, y, size, size)

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)

        (dark_r, dark_g, dark_b) = self.colours[self.m_onColour if self.
                                                m_value else self.m_offColour]

        dark_str = "rgb(%d,%d,%d)" % (dark_r, dark_g, dark_b)
        light_str = "rgb(%d,%d,%d)" % self.adjust(dark_r, dark_g, dark_b)

        shape = self.shapes[self.m_shape] % (dark_str, light_str)
        shape = shape.encode('utf-8')
        self.renderer.load(QByteArray(shape))
        self.renderer.render(painter, bounds)
예제 #6
0
 def paintEvent(self, event):
     # 解决QSS问题
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, option, painter, self)
     super(CustomPaintWidget, self).paintEvent(event)
예제 #7
0
파일: Purchase.py 프로젝트: CaptTwigg/POS
 def paintEvent(self, event):
     "Reimplementation of paintEvent to allow for style sheets"
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
     painter.end()
예제 #8
0
 def paintEvent(self, event):
     """由于继承的问题会导致子控件QWidget无法通过QSS设置样式,需要重写该方法"""
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, option, painter, self)
     QWidget.paintEvent(self, event)
예제 #9
0
def StyledWidget_paintEvent(self, event):
    """A default styled QWidget subclass  paintEvent function.
    """
    opt = QStyleOption()
    opt.initFrom(self)
    painter = QPainter(self)
    self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #10
0
    def paintEvent(self, _):
        opt = QStyleOption()
        opt.initFrom(self)
        painter = QPainter(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)

        if self.show_pieces:
            if len(self.pieces) == 0:  # Nothing to paint
                return

            if len(self.pieces) <= self.width():  # We have less pieces than pixels
                piece_width = self.width() / float(len(self.pieces))
                for i in range(len(self.pieces)):
                    if self.pieces[i]:
                        painter.fillRect(
                            QRect(float(i) * piece_width, 0, math.ceil(piece_width), self.height()), QColor(230, 115, 0)
                        )
            else:  # We have more pieces than pixels, group pieces
                pieces_per_pixel = len(self.pieces) / float(self.width())
                for i in range(self.width()):
                    begin_piece = int(pieces_per_pixel * i)
                    end_piece = int(begin_piece + pieces_per_pixel)
                    piece_sum = 0
                    for j in range(begin_piece, end_piece):
                        piece_sum += self.pieces[j]
                    qt_color = QColor()
                    qt_color.setHsl(26, 255, 128 + 127 * (1 - piece_sum / pieces_per_pixel))
                    painter.fillRect(QRect(i, 0, 10, self.height()), qt_color)
        else:
            painter.fillRect(QRect(0, 0, self.width() * self.fraction, self.height()), QColor(230, 115, 0))
예제 #11
0
    def paintEvent(self, event):
        # Draw backgrounds according to css
        styleOpt = QStyleOption()
        styleOpt.initFrom(self)
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)
        self.style().drawPrimitive(QStyle.PE_Widget, styleOpt, p, self)

        if self.values == None or len(self.values) == 0: return

        # print(len(self.values))

        r = self.rect()
        dx = r.width() / float(self.datapoints - 1)

        # Build a path from the readings
        path = QPainterPath()
        path.moveTo(r.bottomRight())
        i = 0
        for reading in reversed(self.values):
            pt = QPointF(r.width() - i*dx, (1.0 - reading) * r.height())
            path.lineTo(pt)
            i = i + 1
        path.lineTo(path.currentPosition().x(), r.height())
        path.closeSubpath()

        # Use foreground color for graph
        gcolor = styleOpt.palette.color(QPalette.Text)
        p.setBrush(gcolor)
        p.setPen(gcolor)
        p.drawPath(path)
예제 #12
0
def drawIndicatorIcon(palette, style):
    pix = QPixmap(14, 14)
    pix.fill(Qt.transparent)
    branchOption = QStyleOption()
    #r = QRect(QPoint(0, 0), pix.size())
    branchOption.rect = QRect(2, 2, 9, 9) ## ### hardcoded in qcommonstyle.cpp
    branchOption.palette = palette
    branchOption.state = QStyle.State_Children

    p = QPainter()
    ## Draw closed state
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()
    rc = QIcon(pix)
    rc.addPixmap(pix, QIcon.Selected, QIcon.Off)
    ## Draw opened state
    branchOption.state |= QStyle.State_Open
    pix.fill(Qt.transparent)
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()

    rc.addPixmap(pix, QIcon.Normal, QIcon.On)
    rc.addPixmap(pix, QIcon.Selected, QIcon.On)
    return rc
예제 #13
0
 def paintEvent(self, event):
     opt = QStyleOption()
     opt.initFrom(self)
     opt.state |= (QStyle.State_Sunken
                   if self.isDown() else QStyle.State_Raised)
     p = QStylePainter(self)
     p.drawPrimitive(QStyle.PE_Widget, opt)
예제 #14
0
 def getSyleOptions(self):
     options = QStyleOption()
     options.initFrom(self.clazz)
     size = options.rect.size()
     size.transpose()
     options.rect.setSize(size)
     options.features = QStyleOption.SO_Default
     return options
예제 #15
0
 def paintEvent(self, event):
     '''
     Birden çok değer aktarımından sonra işlev arızasını önlemek için, stili ayarlamak için qss kullanmaya devam edebilirsiniz.
     '''
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #16
0
 def paintEvent(self, event):
     painter = QPainter(self)
     option = QStyleOption()
     option.rect = self.rect()
     option.state = QStyle.State_Horizontal
     option.palette = self.palette()
     self.style().drawPrimitive(QStyle.PE_IndicatorToolBarSeparator, option,
                                painter, self)
예제 #17
0
 def paintEvent(self, event):
     """由于继承的问题会导致子控件QWidget无法通过QSS设置样式,需要重写该方法"""
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, option, painter, self)
     QWidget.paintEvent(self, event)
     # super(BaseWidget, self).paintEvent(event)
예제 #18
0
 def paintEvent(self, event):
     '''
     避免多重传值后的功能失效,从而可以继续使用qss设置样式
     '''
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #19
0
 def paintEvent(self, event):
     option = QStyleOption()
     option.initFrom(self)
     painter = QStylePainter(self)
     painter.setRenderHint(QStylePainter.Antialiasing, True)
     painter.drawPrimitive(
         QStyle.PE_Widget if self.testAttribute(Qt.WA_NoSystemBackground)
         else QStyle.PE_Frame, option)
예제 #20
0
    def paintEvent(self, event):
        painter = QPainter(self)
        pixmap = QPixmap().fromImage(self._bgImage, Qt.AutoColor)
        painter.drawPixmap(self.rect(), pixmap)

        opt = QStyleOption()
        opt.initFrom(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
        super().paintEvent(event)
예제 #21
0
 def paintEvent(self, event):
     #Subclasses from QWidget loses their ability to use StyleSheets
     #In order to use the StyleSheets you need to provide a paintEvent to the custom widget.
     #This part of code is based on https://stackoverflow.com/questions/2565963/pyqt4-qwidget-subclass-not-responding-to-new-setstylesheet-background-colour
     opt = QStyleOption()
     #opt.init(self)
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #22
0
 def paintEvent(self, paintEvent):
     """
     This is needed for the widget to pick the stylesheet.
     :type paintEvent: QPaintEvent
     """
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Widget, option, painter, self)
예제 #23
0
 def paintEvent(self, event):
     '''无边框透明后圆角问题'''
     super(FramelessWindow, self).paintEvent(event)
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setPen(QPen(QColor(0, 0, 0, 1), 2 * self.margin))
     painter.drawRect(self.rect())
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #24
0
 def paintEvent(self, pe):
     """
     @Overrides default QWidget method
     :param pe:
     :return:
     """
     o = QStyleOption()
     o.initFrom(self)
     p = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, o, p, self)
예제 #25
0
파일: info.py 프로젝트: gitter-badger/eddy
 def paintEvent(self, paintEvent):
     """
     This is needed for the widget to pick the stylesheet.
     :type paintEvent: QPaintEvent
     """
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Widget, option, painter, self)
예제 #26
0
 def paintEvent(self, paint_event: QPaintEvent):
     """
     Override painEvent in order to support stylesheets.
     :param paint_event:
     :return:
     """
     style_option = QStyleOption()
     style_option.initFrom(self)
     painter = QPainter(self)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Widget, style_option, painter, self)
예제 #27
0
 def paintEvent(self, event):
     super(EditorBase, self).paintEvent(event)
     opt = QStyleOption()
     opt.initFrom(self)
     c = opt.palette.color(QPalette.Window)
     # this should allow changing color directly too
     # as well as saving recoloring when it's already colored
     if self._stylebackgroundColor != c.name():
         self.set_background_color(c.name())
         self.setMarginsBackgroundColor(c.darker(110))
         self._stylebackgroundColor = c.name()
예제 #28
0
 def paintEvent(self, event):
     QToolButton.paintEvent(self, event)
     painter = QPainter(self)
     opt = QStyleOption()
     opt.initFrom(self)
     opt.rect = QRect(6, self.rect().center().y() - 3, 8, 8)
     opt.rect.translate(0, -3)
     style = self.style()
     style.drawPrimitive(QStyle.PE_IndicatorArrowUp, opt, painter, self)
     opt.rect.translate(0, 6)
     style.drawPrimitive(QStyle.PE_IndicatorArrowDown, opt, painter, self)
예제 #29
0
 def paintEvent(self, event):
     """
     self is derived from QWidget, Stylesheets don't work unless \
     paintEvent is reimplemented.y
     at the same time, if self is derived from QFrame, this isn't needed.
     """
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Widget, option, painter, self)
예제 #30
0
 def paintEvent(self, event):
     QToolButton.paintEvent(self, event)
     painter = QPainter(self)
     opt = QStyleOption()
     opt.initFrom(self)
     opt.rect = QRect(6, self.rect().center().y() - 3, 8, 8)
     opt.rect.translate(0, -3)
     style = self.style()
     style.drawPrimitive(QStyle.PE_IndicatorArrowUp, opt, painter, self)
     opt.rect.translate(0, 6)
     style.drawPrimitive(QStyle.PE_IndicatorArrowDown, opt, painter, self)
예제 #31
0
 def paintEvent(self, QPaintEvent):
     """
     self is derived from QWidget, Stylesheets don't work unless \
     paintEvent is reimplemented.y
     at the same time, if self is derived from QFrame, this isn't needed.
     """
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Widget, option, painter, self)
예제 #32
0
파일: main.py 프로젝트: andreyvydra/kaban
    def paintEvent(self, event):
        """ Метод переопределён для корректной работы стилей
        для класса Task, унаследованного от QWidget
        Args:
            event: событие
        """

        opt = QStyleOption()
        opt.initFrom(self)
        qp = QPainter(self)
        style = self.style()
        style.drawPrimitive(QStyle.PE_Widget, opt, qp, self)
예제 #33
0
    def paintEvent(self, paint_event: QPaintEvent):
        if self.p:
            painter = QPainter(self)
            painter.setRenderHint(QPainter.SmoothPixmapTransform)
            painter.drawPixmap(self.rect(), self.p)

        # Support stylesheets
        style_option = QStyleOption()
        style_option.initFrom(self)
        painter = QPainter(self)
        style = self.style()
        style.drawPrimitive(QStyle.PE_Widget, style_option, painter, self)
예제 #34
0
 def paintEvent(self, event):
     """
     重写paintEvent 否则不能使用样式表定义外观
     :param evt:
     :return:
     """
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     # 反锯齿
     painter.setRenderHint(QPainter.Antialiasing)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #35
0
    def paintEvent(self, paint_event):
        """
        A simple override to the `QWidget.paintEvent` required soo the QSS
        rules have effect over `QWidget` subclasses.

        From: http://doc.qt.io/qt-5/stylesheet-reference.html#qwidget-widget

        :type paint_event: PyQt5.QtGui.QPaintEvent
        """
        opt = QStyleOption()
        opt.initFrom(self)
        p = QPainter(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, p, self)
예제 #36
0
    def paintEvent(self, _event):
        """Paint the arrow.

        Args:
            _paint: The QPaintEvent (unused).
        """
        opt = QStyleOption()
        opt.initFrom(self)
        painter = QPainter(self)
        if self._folded:
            elem = QStyle.PE_IndicatorArrowRight
        else:
            elem = QStyle.PE_IndicatorArrowDown
        self.style().drawPrimitive(elem, opt, painter, self)
예제 #37
0
 def paintEvent(self, _event):
     """Paint a grid of helper lines."""
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     pen = QPen(self.color)
     for fraction, style, width in self.LINES:
         pen.setStyle(style)
         pen.setWidth(width)
         painter.setPen(pen)
         x_fraction = int(self.width() * fraction)
         y_fraction = int(self.height() * fraction)
         painter.drawLine(0, y_fraction, self.width(), y_fraction)
         painter.drawLine(x_fraction, 0, x_fraction, self.height())
예제 #38
0
    def paintEvent(self, _event):
        """Paint the arrow.

        Args:
            _paint: The QPaintEvent (unused).
        """
        opt = QStyleOption()
        opt.initFrom(self)
        painter = QPainter(self)
        if self._folded:
            elem = QStyle.PE_IndicatorArrowRight
        else:
            elem = QStyle.PE_IndicatorArrowDown
        self.style().drawPrimitive(elem, opt, painter, self)
예제 #39
0
 def paintEvent(self, event):
     """Paint the widget."""
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     if self._direction == QArrow.UP:
         primitive = QStyle.PE_IndicatorArrowUp
     elif self._direction == QArrow.DOWN:
         primitive = QStyle.PE_IndicatorArrowDown
     elif self._direction == QArrow.LEFT:
         primitive = QStyle.PE_IndicatorArrowLeft
     else:
         primitive = QStyle.PE_IndicatorArrowRight
     painter.setViewTransformEnabled(True)
     self.style().drawPrimitive(primitive, opt, painter, self)
예제 #40
0
    def paint_drop_indicator(self, painter):
        if self.drag_active:
            opt = QStyleOption()
            opt.initFrom(self)
            opt.rect = self.drop_indicator_rect
            rect = opt.rect

            brush = QBrush(QColor(Qt.darkRed))

            if rect.height() == 0:
                pen = QPen(brush, 2, Qt.SolidLine)
                painter.setPen(pen)
                painter.drawLine(rect.topLeft(), rect.topRight())
            else:
                pen = QPen(brush, 2, Qt.SolidLine)
                painter.setPen(pen)
                painter.drawRect(rect)
예제 #41
0
    def paintEvent(self, event):
        # Draw backgrounds according to css
        styleOpt = QStyleOption()
        styleOpt.initFrom(self)
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)
        self.style().drawPrimitive(QStyle.PE_Widget, styleOpt, p, self)

        if self.values == None or len(self.values) == 0: return

        r = self.rect()

        gcolor = styleOpt.palette.color(QPalette.Text)
        p.setBrush(gcolor)
        p.setPen(gcolor)

        for i in range(len(self.values)):
            spacing = 4
            thickness = (r.height() - spacing*(len(self.values)-1)) / len(self.values)
            p.drawRect(QRectF(0, (thickness+spacing) * i, self.values[i]*r.width(), thickness))
예제 #42
0
 def paintEvent(self, event):  # make the widget style aware
     option = QStyleOption()
     option.initFrom(self)
     painter = QStylePainter(self)
     painter.drawPrimitive(QStyle.PE_Widget, option)
예제 #43
0
 def paintEvent(self, event):
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, option, painter, self)
     super(ChildWidget, self).paintEvent(event)
예제 #44
0
 def paintEvent(self, _):
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
예제 #45
0
 def paintEvent(self, pe):
     opt = QStyleOption()
     opt.initFrom(self)
     p = QPainter(self)
     s = self.style()
     s.drawPrimitive(QStyle.PE_Widget, opt, p, self)
예제 #46
0
    def paintEvent(self, event):
        option = QStyleOption()
        option.initFrom(self)

        contents_rect = self.style().subElementRect(QStyle.SE_FrameContents, option, self) or self.contentsRect()  # the SE_FrameContents rect is Null unless the stylesheet defines decorations

        if self.graphStyle == self.BarStyle:
            graph_width = self.__dict__['graph_width'] = int(ceil(float(contents_rect.width()) / self.horizontalPixelsPerUnit))
        else:
            graph_width = self.__dict__['graph_width'] = int(ceil(float(contents_rect.width() - 1) / self.horizontalPixelsPerUnit) + 1)

        max_value = self.__dict__['max_value'] = max(chain([0], *(islice(reversed(graph.data), graph_width) for graph in self.graphs if graph.enabled)))

        if self.graphHeight == self.AutomaticHeight or self.graphHeight < 0:
            graph_height = self.__dict__['graph_height'] = max(self.scaler.get_height(max_value), self.minHeight)
        else:
            graph_height = self.__dict__['graph_height'] = max(self.graphHeight, self.minHeight)

        if self.graphStyle == self.BarStyle:
            height_scaling = float(contents_rect.height()) / graph_height
        else:
            height_scaling = float(contents_rect.height() - self.lineThickness) / graph_height

        painter = QStylePainter(self)
        painter.drawPrimitive(QStyle.PE_Widget, option)

        painter.setClipRect(contents_rect)

        painter.save()
        painter.translate(contents_rect.x() + contents_rect.width() - 1, contents_rect.y() + contents_rect.height() - 1)
        painter.scale(-1, -1)

        painter.setRenderHint(QStylePainter.Antialiasing, self.graphStyle != self.BarStyle)

        for graph in (graph for graph in self.graphs if graph.enabled and graph.data):
            if self.boundary is not None and 0 < self.boundary < graph_height:
                boundary_width = min(5.0/height_scaling, self.boundary-0, graph_height-self.boundary)
                pen_color = QLinearGradient(0, (self.boundary - boundary_width) * height_scaling, 0, (self.boundary + boundary_width) * height_scaling)
                pen_color.setColorAt(0, graph.color)
                pen_color.setColorAt(1, graph.over_boundary_color)
                brush_color = QLinearGradient(0, (self.boundary - boundary_width) * height_scaling, 0, (self.boundary + boundary_width) * height_scaling)
                brush_color.setColorAt(0, self.color_with_alpha(graph.color, self.fillTransparency))
                brush_color.setColorAt(1, self.color_with_alpha(graph.over_boundary_color, self.fillTransparency))
            else:
                pen_color = graph.color
                brush_color = self.color_with_alpha(graph.color, self.fillTransparency)
            dataset = islice(reversed(graph.data), graph_width)
            if self.graphStyle == self.BarStyle:
                lines = [QLineF(x*self.horizontalPixelsPerUnit, 0, x*self.horizontalPixelsPerUnit, y*height_scaling) for x, y in enumerate(dataset)]
                painter.setPen(QPen(pen_color, self.lineThickness))
                painter.drawLines(lines)
            else:
                painter.translate(0, +self.lineThickness/2 - 1)

                if self.smoothEnvelope and self.smoothFactor > 0:
                    min_value = 0
                    max_value = graph_height * height_scaling
                    cx_offset = self.horizontalPixelsPerUnit / 3.0
                    smoothness = self.smoothFactor

                    last_values = deque(3*[next(dataset) * height_scaling], maxlen=3)  # last 3 values: 0 last, 1 previous, 2 previous previous

                    envelope = QPainterPath()
                    envelope.moveTo(0, last_values[0])
                    for x, y in enumerate(dataset, 1):
                        x = x * self.horizontalPixelsPerUnit
                        y = y * height_scaling * (1 - smoothness) + last_values[0] * smoothness
                        last_values.appendleft(y)
                        c1x = x - cx_offset * 2
                        c2x = x - cx_offset
                        c1y = limit((1 + smoothness) * last_values[1] - smoothness * last_values[2], min_value, max_value)  # same gradient as previous previous value to previous value
                        c2y = limit((1 - smoothness) * last_values[0] + smoothness * last_values[1], min_value, max_value)  # same gradient as previous value to last value
                        envelope.cubicTo(c1x, c1y, c2x, c2y, x, y)
                else:
                    envelope = QPainterPath()
                    envelope.addPolygon(QPolygonF([QPointF(x*self.horizontalPixelsPerUnit, y*height_scaling) for x, y in enumerate(dataset)]))

                if self.fillEnvelope or graph.fill_envelope:
                    first_element = envelope.elementAt(0)
                    last_element = envelope.elementAt(envelope.elementCount() - 1)
                    fill_path = QPainterPath()
                    fill_path.moveTo(last_element.x, last_element.y)
                    fill_path.lineTo(last_element.x + 1, last_element.y)
                    fill_path.lineTo(last_element.x + 1, -self.lineThickness)
                    fill_path.lineTo(-self.lineThickness, -self.lineThickness)
                    fill_path.lineTo(-self.lineThickness, first_element.y)
                    fill_path.connectPath(envelope)
                    painter.fillPath(fill_path, brush_color)

                painter.strokePath(envelope, QPen(pen_color, self.lineThickness, join=Qt.RoundJoin))

                painter.translate(0, -self.lineThickness/2 + 1)

        if self.boundary is not None and self.boundaryColor:
            painter.setRenderHint(QStylePainter.Antialiasing, False)
            painter.setPen(QPen(self.boundaryColor, 1.0))
            painter.drawLine(0, self.boundary*height_scaling, contents_rect.width(), self.boundary*height_scaling)

        painter.restore()

        # queue the 'updated' signal to be emitted after returning to the main loop
        QMetaObject.invokeMethod(self, 'updated', Qt.QueuedConnection)
예제 #47
0
파일: otr.py 프로젝트: AGProjects/blink-qt
 def paintEvent(self, event):
     option = QStyleOption()
     option.initFrom(self)
     painter = QStylePainter(self)
     painter.setRenderHint(QStylePainter.Antialiasing, True)
     painter.drawPrimitive(QStyle.PE_Widget if self.testAttribute(Qt.WA_NoSystemBackground) else QStyle.PE_Frame, option)