Ejemplo n.º 1
0
    def line_number_area_paint_event(self, event: QPaintEvent):
        log.debug("")
        painter = QPainter(self.line_number_area)
        painter.fillRect(event.rect(), Qt.lightGray)
        block = self.firstVisibleBlock()
        block_number = block.blockNumber()
        top = self.blockBoundingGeometry(block).translated(
            self.contentOffset()).top()
        bottom = top + self.blockBoundingRect(block).height()
        log.debug(top)
        log.debug(bottom)

        # print(block.isValid(), top <= event.rect().bottom())
        # print(block.isVisible(), bottom >= event.rect().top())

        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                number = str(block_number + 1)
                # print(number)
                painter.setPen(Qt.black)
                painter.drawText(0, top, self.line_number_area.width(),
                                 self.fontMetrics().height(), Qt.AlignRight,
                                 number)
            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            block_number += 1
Ejemplo n.º 2
0
 def paintEvent(self, e: QtGui.QPaintEvent):
     if self.isVisible():
         block = self.editor.firstVisibleBlock()
         height = self.editor.fontMetrics().height()
         block_number = block.blockNumber()
         painter = QtGui.QPainter(self)
         painter.fillRect(e.rect(), QtGui.QColor("#ACDED5"))
         # painter.drawRect(0, 0, e.rect().width(), e.rect().height())
         font = self.editor.font()
         current_block = self.editor.textCursor().block().blockNumber() + 1
         condition = True
         while block.isValid() and condition:
             block_geometry = self.editor.blockBoundingGeometry(block)
             offset = self.editor.contentOffset()
             top = block_geometry.translated(offset).top()
             block_number += 1
             rect = QtCore.QRect(0, top, self.width(), height)
             if block_number == current_block:
                 font.setBold(True)
             else:
                 font.setBold(False)
             painter.setFont(font)
             painter.drawText(rect, QtCore.Qt.AlignRight,
                              '%i' % block_number)
             if top > e.rect().bottom():
                 condition = False
             block = block.next()
         painter.end()
Ejemplo n.º 3
0
    def paintEvent(self, evt: QtGui.QPaintEvent) -> None:
        painter = QtGui.QPainter(self)
        try:
            painter.fillRect(evt.rect(), self._bg_color)
            painter.translate(-self.xOffset(), 0)
            self._paint(painter, evt.rect().translated(self.xOffset(), 0))

        finally:
            painter.end()
Ejemplo n.º 4
0
    def paint_event(self, event: QtGui.QPaintEvent) -> None:
        self.update_pixmap()

        painter = QtGui.QPainter(self.widget)
        painter.begin(self.widget)
        painter.drawPixmap(0, 0, self.pixmap)
        painter.end()

        event.accept()
Ejemplo n.º 5
0
    def paintEvent(self, e: QtGui.QPaintEvent):
        painter = QtGui.QPainter(self)
        color = (r, g, b, a) = (255, 0, 0, 16)
        painter.fillRect(e.rect(), QColor(r, g, b, a))

        if self.m_infocus:
            rect = e.rect()
            rect.adjust(0,0,-1,-1)
            painter.setPen(QColor(r, g, b))
            painter.drawRect(rect)
Ejemplo n.º 6
0
    def paintEvent(self, paintEvent: QPaintEvent):
        pen = QPen()
        pen.setJoinStyle(Qt.RoundJoin)
        pen.setCapStyle(Qt.RoundCap)
        painter = QPainter(self)
        painter.translate(self.paintOffset)
        painter.setBackgroundMode(Qt.TransparentMode)
        painter.setRenderHint(QPainter.Antialiasing)

        if self.nodes is not None:
            painted = set()

            def paintNode(node):
                nonlocal painter, painted
                if node in painted:
                    return
                painted.add(node)
                for link in node.links:
                    if link not in painted:
                        painter.drawLine(node.point, link.point)
                        paintNode(link)

            color = self.palette().color(QPalette.Dark)
            pen.setColor(color)
            pen.setWidth(0.50 * self.paintStep)
            painter.setPen(pen)
            for node in self.nodes.values():
                if paintEvent.region().contains(node.point):
                    paintNode(node)

        if self.startNode is not None:
            color = self.palette().color(QPalette.Dark)
            pen.setColor(color)
            pen.setWidth(0.75 * self.paintStep)
            painter.setPen(pen)
            if paintEvent.region().contains(self.startNode.point):
                painter.drawPoint(self.startNode.point)

        if self.finishNode is not None and paintEvent.region().contains(
                self.finishNode.point):
            color = self.palette().color(QPalette.Dark).darker(120)
            pen.setColor(color)
            pen.setWidth(0.75 * self.paintStep)
            painter.setPen(pen)
            painter.drawPoint(self.finishNode.point)

        if self.player is not None:
            color = self.palette().color(QPalette.Highlight)
            color.setAlpha(196)
            pen.setColor(color)
            pen.setWidth(0.90 * self.paintStep)
            painter.setPen(pen)
            painter.drawPoint(self.player)

        del painter, pen
Ejemplo n.º 7
0
    def paintEvent(self, evt: QtGui.QPaintEvent) -> None:
        super().paintEvent(evt)

        painter = QtGui.QPainter(self)
        try:
            painter.fillRect(evt.rect(), Qt.white)

            painter.translate(-self.xOffset(), 0)

            self.renderTimeGrid(painter,
                                evt.rect().translated(self.xOffset(), 0),
                                show_numbers=True)

            # loop markers
            loop_start_time = self.__player_state.loopStartTime()
            if loop_start_time is not None:
                x = self.timeToX(loop_start_time)
                painter.setBrush(Qt.black)
                painter.setPen(Qt.NoPen)
                polygon = QtGui.QPolygon()
                polygon.append(QtCore.QPoint(x, 0))
                polygon.append(QtCore.QPoint(x + 7, 0))
                polygon.append(QtCore.QPoint(x + 2, 5))
                polygon.append(QtCore.QPoint(x + 2, self.height() - 5))
                polygon.append(QtCore.QPoint(x + 7, self.height()))
                polygon.append(QtCore.QPoint(x, self.height()))
                painter.drawPolygon(polygon)

            loop_end_time = self.__player_state.loopEndTime()
            if loop_end_time is not None:
                x = self.timeToX(loop_end_time)
                painter.setBrush(Qt.black)
                painter.setPen(Qt.NoPen)
                polygon = QtGui.QPolygon()
                polygon.append(QtCore.QPoint(x - 6, 0))
                polygon.append(QtCore.QPoint(x + 2, 0))
                polygon.append(QtCore.QPoint(x + 2, self.height()))
                polygon.append(QtCore.QPoint(x - 6, self.height()))
                polygon.append(QtCore.QPoint(x, self.height() - 6))
                polygon.append(QtCore.QPoint(x, 6))
                painter.drawPolygon(polygon)

            # playback time
            x = self.timeToX(self.__player_state.currentTime())
            painter.fillRect(x, 0, 2, self.height(), QtGui.QColor(0, 0, 160))

        finally:
            painter.end()
Ejemplo n.º 8
0
 def _draw_text(self, event: QtG.QPaintEvent, painter: QtG.QPainter):
     metrics = QtG.QFontMetrics(self.font())
     elided_text = metrics.elidedText(self.text(), self._elide_mode,
                                      self.width())
     # noinspection PyTypeChecker
     painter.drawText(event.rect(),
                      self.alignment() | QtC.Qt.AlignVCenter, elided_text)
Ejemplo n.º 9
0
 def paintEvent(self, event: QPaintEvent) -> None:
     qp = QPainter()
     qp.begin(self)
     qp.setRenderHint(QPainter.Antialiasing)
     qp.fillRect(event.rect(), QBrush(Qt.white))  # or changed to Qt.white
     self._drawPeptide(qp)
     qp.end()
Ejemplo n.º 10
0
    def paint_all(
        self,
        event: QPaintEvent,
        bindings,
        figures: Dict[str, Figure],
        selected_figures: list,
        created_figure: Optional[Figure] = None,
    ):
        painter = QPainter()
        painter.begin(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.fillRect(event.rect(), QBrush(QColor(255, 255, 255)))
        painter.save()
        painter.translate(*self._center)

        # Paint all
        paint.write_coordinates_near_pointer(painter, self._mouse_xy)

        for figure in figures.values():
            paint.paint_figure(painter, figure, 'basic')

        paint.paint_bindings(painter, figures, bindings)

        # Paint painted figure
        if created_figure is not None:
            paint.paint_figure(painter, created_figure, 'created')

        # Paint selected figure
        for selected_figure in selected_figures:
            paint.paint_figure(painter, selected_figure, 'selected')

        # Finish painting
        painter.restore()
        painter.end()
Ejemplo n.º 11
0
 def paintEvent(self, event: QtGui.QPaintEvent):
     # 通过一个绘图事件实现绘图。
     paint = QtGui.QPainter()
     paint.begin(self)
     paint.setPen(QtGui.QColor(168, 34, 3))
     paint.setFont(QtGui.QFont("STLiti", 20))
     paint.drawText(event.rect(), QtCore.Qt.AlignCenter, self.text)
     paint.end()
Ejemplo n.º 12
0
    def drawText(self, e: QtGui.QPaintEvent, qp):
        qp.setPen(QColor(168, 34, 3))
        qp.setFont(QFont('Decorative', 10))
        qp.drawText(e.rect(), Qt.AlignCenter, self.text)

        size = self.size()

        for i in range(1000):
            x = random.randint(1, size.width() - 1)
            y = random.randint(1, size.height() - 1)
            qp.drawPoint(x, y)
Ejemplo n.º 13
0
    def lineNumberAreaPaintEvent(self, event: QtGui.QPaintEvent) -> None:
        painter = QtGui.QPainter(self.__line_number_area)
        painter.fillRect(event.rect(), Qt.lightGray)
        block = self.firstVisibleBlock()
        block_number = block.blockNumber()
        offset = self.contentOffset()
        top = int(self.blockBoundingGeometry(block).translated(offset).top())
        bottom = top + int(self.blockBoundingRect(block).height())

        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                number = str(block_number + 1)
                painter.setPen(Qt.black)
                width = self.__line_number_area.width()
                height = self.fontMetrics().height()
                painter.drawText(0, top, width, height, Qt.AlignRight, number)

            block = block.next()
            top = bottom
            bottom = top + int(self.blockBoundingRect(block).height())
            block_number += 1
Ejemplo n.º 14
0
    def paintEvent(self, event: QPaintEvent):
        p = QPainter(self)
        if FLAT_STYLE:
            p.fillRect(event.rect(), BASE_COLOR)

        current = self._currentIndex
        paintTab = self.paintTab
        for i, tab in enumerate(self._tabs):
            if i != current:
                paintTab(p, i)

        if current != -1:
            paintTab(p, current)
Ejemplo n.º 15
0
    def gutter_paint_event(self, event: QPaintEvent):
        painter = QPainter(self.gutter)
        painter.fillRect(event.rect(), QColor(Qt.lightGray).lighter(125))

        block = self.firstVisibleBlock()
        block_number = block.blockNumber()
        top = self.blockBoundingGeometry(block).translated(
            self.contentOffset()).top()
        bottom = top + self.blockBoundingRect(block).height()

        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                line_number = block_number + 1
                painter.setPen(Qt.black)
                painter.drawText(0, top, self.gutter.width(),
                                 self.fontMetrics().height(), Qt.AlignRight,
                                 str(line_number))

            block = block.next()
            top = bottom
            bottom = top + self.blockBoundingRect(block).height()
            block_number += 1
Ejemplo n.º 16
0
    def paintEvent(self, event: QPaintEvent) -> None:
        """
        Overridden paintEvent of QWidget which repainting numbers in bar.

        Args:
            event(QPaintEvent): qt event object with event data
        """
        if self.isVisible():
            block = self.editor.firstVisibleBlock()  # first visible block of editor
            line_number = block.blockNumber()  + 1# line of first visible block
            font_height = self.fontMetrics().height()  # height of used font for line numbers

            painter = QPainter(self)  # painter which will draw bar and numbers
            painter.fillRect(event.rect(), QColor("#d3d7cf"))  # fill the line number bar with some color TODO: configurable
            painter.drawRect(0, 0, event.rect().width() - 1, event.rect().height() - 1)  # draw line number bar border
            font = painter.font()  # actual font

            current_block = self.editor.textCursor().block().blockNumber() + 1  # line of actual block under cursor

            condition = True
            while block.isValid() and condition:
                block_geometry = self.editor.blockBoundingGeometry(block)
                offset = self.editor.contentOffset()
                block_top = block_geometry.translated(offset).top()

                number_rect = QRect(5, block_top, self.width() - 5, font_height)  # rectangle for the line number
                font.setBold(line_number == current_block)  # set bold line number for actual line

                painter.setFont(font)
                painter.drawText(number_rect, Qt.AlignLeft, str(line_number))

                line_number += 1

                condition = block_top <= event.rect().bottom()

                block = block.next()

            painter.end()
Ejemplo n.º 17
0
    def drawBackground(self, qp: QPainter, event: QPaintEvent):
        qp.fillRect(event.rect(), QColor(255, 255, 255))
        pen = QPen(QColor(223, 223, 223), 1, Qt.SolidLine)
        qp.setPen(pen)
        x1 = 15
        y1 = 15
        x2 = event.rect().width() - 30
        y2 = event.rect().height() - 30
        qp.drawLine(x1, y1, x2, y1)
        qp.drawLine(x2, y1, x2, y2)
        qp.drawLine(x1, y1, x1, y2)
        qp.drawLine(x1, y2, x2, y2)

        pen = QPen(QColor(223, 223, 223), 1, Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(x1, (y1 + y2) / 4, x2, (y1 + y2) / 4)
        qp.drawLine(x1, (y1 + y2) * 3 / 4, x2, (y1 + y2) * 3 / 4)
        qp.drawLine((x1 + x2) / 4, y1, (x1 + x2) / 4, y2)
        qp.drawLine((x1 + x2) / 2, y1, (x1 + x2) / 2, y2)
        qp.drawLine((x1 + x2) * 3 / 4, y1, (x1 + x2) * 3 / 4, y2)
        pen = QPen(QColor(0, 0, 0), 1, Qt.DotLine)
        qp.setPen(pen)
        qp.drawLine(x1, (y1 + y2) / 2, x2, (y1 + y2) / 2)
Ejemplo n.º 18
0
    def paintEvent(self, event: QPaintEvent) -> None:
        """Process the paint event by repainting this Widget.

        Parameters
        ----------
        event : QPaintEvent
        """
        super().paintEvent(event)  # make sure the frame is painted

        if self._features is not None:
            painter = QPainter()
            painter.begin(self)
            self._drawFeatures(painter, event.rect())
            painter.end()
Ejemplo n.º 19
0
    def paintEvent(self, event: QPaintEvent) -> None:
        """Process the paint event by repainting this Widget.

        Parameters
        ----------
        event : QPaintEvent
        """
        super().paintEvent(event)  # make sure the frame is painted

        if True:  # self._autoencoder is not None
            painter = QPainter()
            painter.begin(self)
            self._drawAutoencoder(painter, event.rect())
            painter.end()
Ejemplo n.º 20
0
    def statusAreaPaintEvent(self, event: QPaintEvent):
        painter = QPainter(self._statusArea)
        painter.fillRect(event.rect(), Qt.lightGray)

        block = self.firstVisibleBlock()
        top = qRound(
            self.blockBoundingGeometry(block).translated(
                self.contentOffset()).top())
        bottom = top + qRound(self.blockBoundingRect(block).height())

        while block.isValid() and top <= event.rect().bottom():
            if block.isVisible() and bottom >= event.rect().top():
                painter.setPen(Qt.red)
                painter.drawText(
                    0,
                    top,
                    self._statusArea.width(),
                    self.fontMetrics().height(),
                    Qt.AlignRight,
                    MARK if block.userState() == self._State.Error else NOMARK,
                )
            block = block.next()
            top = bottom
            bottom = top + qRound(self.blockBoundingRect(block).height())
    def paintEvent(self, paint_event: QPaintEvent):
        super().paintEvent(paint_event)

        if self._pixmap is None:
            return

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

        pix_size: QSize = self._pixmap.size()
        pix_size.scale(paint_event.rect().size(), Qt.KeepAspectRatio)

        scaled_pix: QPixmap = self._pixmap.scaled(pix_size, Qt.KeepAspectRatio,
                                                  Qt.SmoothTransformation)
        painter.drawPixmap(QPoint(), scaled_pix)
Ejemplo n.º 22
0
 def lineNumberAreaPaintEvent(self, event: QtGui.QPaintEvent):
     painter = QtGui.QPainter(self.lineNumberArea)
     painter.fillRect(event.rect(), QtCore.Qt.lightGray)
     block = self.firstVisibleBlock()
     blockNumber = block.blockNumber()
     top = int(
         self.blockBoundingGeometry(block).translated(
             self.contentOffset()).top())
     bottom = top + int(self.blockBoundingRect(block).height())
     while block.isValid() and top <= event.rect().bottom():
         if block.isVisible() and bottom >= event.rect().top():
             number = format(blockNumber + 1, "d")
             painter.setPen(QtCore.Qt.darkGray)
             font = painter.font()
             font.setWeight(QtGui.QFont.Bold)
             painter.setFont(font)
             painter.drawText(0, top,
                              self.lineNumberArea.width() - 3,
                              self.fontMetrics().height(),
                              QtCore.Qt.AlignRight, number)
         block = block.next()
         top = bottom
         bottom = top + int(self.blockBoundingRect(block).height())
         blockNumber += 1
Ejemplo n.º 23
0
    def paintEvent(self, event: QPaintEvent) -> NoReturn:
        rect: QRect = event.rect()
        spacing = 25

        paint = QPainter()
        paint.begin(self)
        for i in range(rect.x(), rect.x() + rect.width() + spacing, spacing):
            for j in range(rect.y(),
                           rect.y() + rect.height() + spacing, spacing):
                paint.drawPoint(
                    QPointF(
                        int(i / spacing) * spacing,
                        int(j / spacing) * spacing))

        pen = QPen(Qt.black, 3, Qt.SolidLine, Qt.RoundCap)
        for wire in WorkspaceView.wires:
            pen.setColor(Qt.blue if wire.selected else Qt.black)
            paint.setPen(pen)
            paint.drawLine(wire.output, wire.input)
        paint.end()
Ejemplo n.º 24
0
    def paintEvent(self, event: QPaintEvent):
        if self.isVisible():
            block: QTextBlock = self.editor.firstVisibleBlock()
            height: int = self.fontMetrics().height()
            number: int = block.blockNumber()

            painter = QPainter(self)
            painter.fillRect(event.rect(), QColor(53, 53, 53))
            # painter.drawRect(0, 0, event.rect().width() - 1, event.rect().height() - 1)
            font = painter.font()
            font.setPointSize(15)
            for blocks in self.editor.currentlyVisibleBlocks:
                bl: QTextBlock = blocks[-1]
                blockGeometry: QRectF = self.editor.blockBoundingGeometry(bl)
                offset: QPointF = self.editor.contentOffset()
                blockTop: float = float(
                    blockGeometry.translated(offset).top() + 2)
                rect: QRect = QRect(0, blockTop, self.width(), height)
                painter.drawText(rect, Qt.AlignRight,
                                 str(bl.blockNumber() + 1))

            painter.end()
Ejemplo n.º 25
0
    def canvasPaintEvent(self, ev : QPaintEvent):
        print(self.counter, '  ', end='')
        self.counter += 1
        repaintRect = ev.rect()
        repaintArea = Rectangle(repaintRect.x(), repaintRect.y(), repaintRect.width(),
                repaintRect.height())

        painter = QPainter(self.w)

        thumbRequested = False
        cells = self.layoutEngine.getVisibleCells(repaintArea)
        for cellNum, cell in cells.items():
            thumb = self.items[cellNum]
            if thumb.getPath() in self.thumbs:
                self.drawThumnail(cellNum, self.thumbs[thumb.getPath()], thumb, cell, painter)
            else:
                if not thumbRequested:

                    self.needThumb.emit(cellNum, thumb.getPath())
                    thumbRequested = True
                self.drawThumnail(cellNum, self.noThumbPixmap, self.items[cellNum],
                        cell, painter)
Ejemplo n.º 26
0
    def canvasPaintEvent(self, ev: QPaintEvent):
        print(self.counter, '  ', end='')
        self.counter += 1
        repaintRect = ev.rect()
        repaintArea = Rectangle(repaintRect.x(), repaintRect.y(),
                                repaintRect.width(), repaintRect.height())

        painter = QPainter(self.w)

        thumbRequested = False
        cells = self.layoutEngine.getVisibleCells(repaintArea)
        for cellNum, cell in cells.items():
            thumb = self.items[cellNum]
            if thumb.getPath() in self.thumbs:
                self.drawThumnail(cellNum, self.thumbs[thumb.getPath()], thumb,
                                  cell, painter)
            else:
                if not thumbRequested:

                    self.needThumb.emit(cellNum, thumb.getPath())
                    thumbRequested = True
                self.drawThumnail(cellNum, self.noThumbPixmap,
                                  self.items[cellNum], cell, painter)
Ejemplo n.º 27
0
	def paintEvent(self, evt):
		"""Change event which only fires when visual change happens.
			
			This fixes the normal valueChanged event firing 3-8 times
			per frame, when dragging the slider."""
		
		
		#print('frame draw time', time.perf_counter()-self._fpsMonitorLastFrame, 'sec')
		self._fpsMonitorLastFrame = time.perf_counter()
		
		clippedEvt = QPaintEvent(self.visibleRegion())
		super().paintEvent(clippedEvt)
		
		val = self.value()
		if val != self.__lastValue:
			self.__lastValue = val
			self.debounce.valueChanged.emit(val)
			if self._userGeneratedEvent:
				self._userGeneratedEvent = False
				self.debounce.sliderMoved.emit(val)
			
			#Move the focus ring with the slider.
			self.tryRefocus()
Ejemplo n.º 28
0
 def paintEvent(self, e: QtGui.QPaintEvent):
     painter = QtGui.QPainter(self)
     rect = e.rect()
     rect.adjust(0, 0, -1, -1)
     painter.setPen(self.pen)
     painter.drawRect(rect)
Ejemplo n.º 29
0
 def paintEvent(self, event: QtGui.QPaintEvent) -> None:
     painter = QtGui.QPainter(self.label.pixmap())
     painter.drawImage(event.rect(), self.image, self.rect())
Ejemplo n.º 30
0
 def draw(self, q_painter: QtGui.QPainter, q_paint_event: QtGui.QPaintEvent):
     if self.visible:
         self._q_painter = q_painter
         q_painter.setRenderHint(QtGui.QPainter.Antialiasing)
         self._window_rect = q_paint_event.rect()
         self._build()
Ejemplo n.º 31
0
    def paintEvent(self, event: QPaintEvent):
        _start = perf_counter()
        num = self.num_tabs
        selected = self.selected
        arrow_width = self._arrow_width
        height = self.height()
        width = self._button_width
        first_width = self._first_button_width
        button = self._button_path
        button_box = QRect(0, 0, width + arrow_width, height)
        first_box = QRect(0, 0, first_width + arrow_width, height)
        icon_area = QRect(arrow_width + 10, 0, max(48, width / 2), height)
        text_box = QRect(arrow_width, 0, width - arrow_width, height)
        text_flags = Qt.AlignCenter | Qt.AlignVCenter
        states = self.states

        painter = QPainter(self)
        region = event.region()
        painter.setClipRegion(region)
        #torender = self._tabs_within(event.region())
        #print("regions:")
        #for rect in event.region().rects():
        #    print(" -  ", rect)
        #painter.setPen(Qt.NoPen)
        painter.setPen(
            QPen(Qt.black, 2, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
        titleFont = painter.font()
        titleFont.setPointSizeF(14)
        titleFont.setBold(True)
        painter.setFont(titleFont)

        painter.translate(num * width + first_width, 0)

        if region.intersects(painter.transform().mapRect(button_box)):
            painter.setBrush(states[num].get_color(num == selected))
            painter.drawPath(self._last_button_path)

        for i in reversed(range(num)):
            painter.translate(-width, 0)
            if not region.intersects(painter.transform().mapRect(button_box)):
                continue

            painter.setBrush(states[i].get_color(i == selected))
            painter.drawPath(button)

            if states[i].state == State.ACTIVE:
                painter.save()
                painter.setPen(Qt.NoPen)
                gw = (width + self._arrow_width) * 2
                gradient = QLinearGradient(0, 0, gw, 0)
                value = self._working_anim.value
                gradient.setColorAt(max(0.0, value - 0.2),
                                    QColor(255, 255, 255, 0))
                gradient.setColorAt(value, QColor(255, 255, 255, 180))
                gradient.setColorAt(min(1.0, value + 0.2),
                                    QColor(255, 255, 255, 0))
                brush = QBrush(gradient)
                brush.setTransform(brush.transform().translate(-gw / 4, 0))
                gradient_height = int(height * 0.2)
                painter.setBrush(brush)
                #painter.setClipRect(0, 0, width+self._arrow_width, gradient_height)
                #painter.drawPath(button)
                #painter.setClipRect(0, height-gradient_height, width+self._arrow_width, gradient_height)
                painter.drawPath(button)
                self._active_box = painter.transform().mapRect(button_box)
                painter.restore()

            #if states[i].icon:
            #    states[i].icon.paint(painter, icon_area)

            text = states[i].text
            if text:
                _, _, short = text.rpartition('-')
                painter.drawText(text_box, text_flags, short.capitalize())

        if region.intersects(first_box):
            painter.resetTransform()
            painter.setBrush(State.UNKNOWN.get_color(-1 == selected))
            painter.drawPath(self._first_button_path)

            if self.is_running:
                icon = self.style().standardIcon(QStyle.SP_MediaStop)
            else:
                icon = self.style().standardIcon(QStyle.SP_MediaPlay)

            size = min(self._first_button_width, self.height()) * 0.8
            painter.translate(5, (self.height() - size) / 2)
            icon.paint(painter, QRect(0, 0, size, size))

        _end = perf_counter()
        if not self._paint_times:
            self._paint_times = times = []
        else:
            times = self._paint_times
        times.append(_end - _start)
        if len(times) > 60:
            avg = sum(times) / len(times) * 1000000
            print("Average render time %.2fns" % (avg, ))
            self._paint_times = None