示例#1
0
 def addRegion(self, start: int, end: int) -> None:
     x = QStyle.sliderPositionFromValue(self.minimum(), self.maximum(), start, self.width())
     y = (self.height() - self._regionHeight) / 2
     width = QStyle.sliderPositionFromValue(self.minimum(), self.maximum(), end, self.width()) - x
     height = self._regionHeight
     path = QPainterPath()
     path.addRect(x, y + 3, width, height)
     self._regions.append(path)
     self.update()
示例#2
0
    def paintEvent(self, e):
        painter = QPainter(self)

        brush = QtGui.QBrush()
        brush.setColor(QColor('black'))
        brush.setStyle(Qt.SolidPattern)
        painter.setBrush(brush)
        rect = QtCore.QRect(0, 0,
                            painter.device().width(),
                            painter.device().height())
        painter.fillRect(rect, brush)

        keyframes_indices = self.parent.selected_text_template.keyframes.keyframes_frames_indices
        slider = self.parent.frames_slider

        pen = QPen()
        pen.setWidth(5)
        pen.setColor(QColor('red'))
        painter.setPen(pen)

        brush = QtGui.QBrush()
        brush.setColor(QColor('red'))
        brush.setStyle(Qt.SolidPattern)
        painter.setBrush(brush)

        for frame_ind in keyframes_indices:
            position = QStyle.sliderPositionFromValue(slider.minimum(),
                                                      slider.maximum(),
                                                      frame_ind,
                                                      slider.width())
            painter.drawEllipse(position, 10, 2, 2)

        painter.end()
示例#3
0
    def paintEvent(self, event):

        bw = float(self._border_width)
        br = self._border_radius

        val = self.value()
        if self.orientation() == Qt.Horizontal:
            w = QStyle.sliderPositionFromValue(self.minimum(), self.maximum(),
                                               val, self.width())
            h = self.height()
            rect = QRectF(bw / 2, bw / 2, w - bw, h - bw)
        else:
            w = self.width()
            h = self.height() - QStyle.sliderPositionFromValue(
                self.minimum(), self.maximum(), val, self.height())
            rect = QRectF(bw / 2, h - bw / 2, w - bw, self.height() - bw)

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

        # draw the load meter value bar
        p.setPen(Qt.transparent)
        p.setBrush(self.gradient)
        p.drawRoundedRect(rect, br, br)

        # draw the border
        p.setBrush(Qt.transparent)
        border_pen = QPen()
        border_pen.setWidth(bw)
        border_pen.setColor(self._border_color)
        p.setPen(border_pen)
        rect = QRectF(bw / 2, bw / 2, self.width() - bw, self.height() - bw)
        p.drawRoundedRect(rect, br, br)

        # draw the load percentage text
        p.setPen(self._text_color)
        if self.orientation() == Qt.Vertical:
            p.rotate(-90)
            p.drawText(-self.height(), 0, self.height(), self.width(),
                       Qt.AlignCenter, self.text())
        else:
            p.drawText(0, 0, self.width(), self.height(), Qt.AlignCenter,
                       self.text())
示例#4
0
    def paintEvent(self, e):

        super(LabeledSlider, self).paintEvent(e)

        style = self.sl.style()
        painter = QPainter(self)
        st_slider = QStyleOptionSlider()
        st_slider.initFrom(self.sl)
        st_slider.orientation = self.sl.orientation()

        length = style.pixelMetric(QStyle.PM_SliderLength, st_slider, self.sl)
        available = style.pixelMetric(QStyle.PM_SliderSpaceAvailable,
                                      st_slider, self.sl)

        for v, v_str in self.levels:

            # get the size of the label
            rect = painter.drawText(QRect(), Qt.TextDontPrint, v_str)

            if self.sl.orientation() == Qt.Horizontal:
                # I assume the offset is half the length of slider, therefore
                # + length//2
                x_loc = QStyle.sliderPositionFromValue(self.sl.minimum(),
                                                       self.sl.maximum(), v,
                                                       available) + length // 2

                # left bound of the text = center - half of text width + L_margin
                left = x_loc - rect.width() // 2 + self.left_margin
                bottom = self.rect().bottom()

                # enlarge margins if clipping
                if v == self.sl.minimum():
                    if left <= 0:
                        self.left_margin = rect.width() // 2 - x_loc
                    if self.bottom_margin <= rect.height():
                        self.bottom_margin = rect.height()

                    self.layout.setContentsMargins(self.left_margin,
                                                   self.top_margin,
                                                   self.right_margin,
                                                   self.bottom_margin)

                if v == self.sl.maximum(
                ) and rect.width() // 2 >= self.right_margin:
                    self.right_margin = rect.width() // 2
                    self.layout.setContentsMargins(self.left_margin,
                                                   self.top_margin,
                                                   self.right_margin,
                                                   self.bottom_margin)

            else:
                y_loc = QStyle.sliderPositionFromValue(self.sl.minimum(),
                                                       self.sl.maximum(),
                                                       v,
                                                       available,
                                                       upsideDown=True)

                bottom = y_loc + length // 2 + rect.height(
                ) // 2 + self.top_margin - 3
                # there is a 3 px offset that I can't attribute to any metric

                left = self.left_margin - rect.width()
                if left <= 0:
                    self.left_margin = rect.width() + 2
                    self.layout.setContentsMargins(self.left_margin,
                                                   self.top_margin,
                                                   self.right_margin,
                                                   self.bottom_margin)

            pos = QPoint(left, bottom)
            painter.drawText(pos, v_str)

        return