コード例 #1
0
 def paintEvent(self, event: QPaintEvent) -> None:
     painter = QStylePainter(self)
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     if self.tickPosition() != QSlider.NoTicks:
         x = 4
         for i in range(self.minimum(), self.width(), x):
             if i % 5 == 0:
                 h = 18
                 w = 1
                 z = 8
             else:
                 h = 7
                 w = 0.8
                 z = 15
             pen = QPen(QColor('#444'))
             pen.setWidthF(w)
             painter.setPen(pen)
             if self.tickPosition() in (QSlider.TicksBothSides, QSlider.TicksAbove):
                 y = self.rect().top() + z
                 painter.drawLine(x, y, x, y + h)
             if self.tickPosition() in (QSlider.TicksBothSides, QSlider.TicksBelow):
                 y = self.rect().bottom() - z
                 painter.drawLine(x, y, x, y - h)
             x += 10
     opt.subControls = QStyle.SC_SliderGroove
     painter.drawComplexControl(QStyle.CC_Slider, opt)
     opt.subControls = QStyle.SC_SliderHandle
     painter.drawComplexControl(QStyle.CC_Slider, opt)
コード例 #2
0
    def paintEvent(self, ev):
        if self.min is not None and self.max is not None:
            opt = QStyleOptionSlider()
            self.initStyleOption(opt)

            opt.subControls = QStyle.SC_SliderGroove | QStyle.SC_SliderHandle
            if self.tickPosition() != self.NoTicks:
                opt.subControls |= QStyle.SC_SliderTickmarks

            groove_rect = self.style().subControlRect(
                    QStyle.CC_Slider,
                    opt,
                    QStyle.SC_SliderGroove,
                    self
                    )

            rect = QRect(
                    groove_rect.left() + self.min * groove_rect.width(),
                    groove_rect.top(),
                    (self.max-self.min) * groove_rect.width(),
                    groove_rect.height()
                    )
            painter = QPainter(self)

            painter.fillRect(rect, QBrush(Qt.red))

        super(ColorRangeSlider, self).paintEvent(ev)
コード例 #3
0
ファイル: videoslider.py プロジェクト: julianrichen/vidcutter
 def paintEvent(self, event: QPaintEvent) -> None:
     painter = QStylePainter(self)
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     if self.tickPosition() != QSlider.NoTicks:
         x = 4
         for i in range(self.minimum(), self.width(), x):
             if i % 5 == 0:
                 h = 18
                 w = 1
                 z = 8
             else:
                 h = 7
                 w = 0.8
                 z = 15
             pen = QPen(QColor('#444'))
             pen.setWidthF(w)
             painter.setPen(pen)
             if self.tickPosition() in (QSlider.TicksBothSides, QSlider.TicksAbove):
                 y = self.rect().top() + z
                 painter.drawLine(x, y, x, y + h)
             if self.tickPosition() in (QSlider.TicksBothSides, QSlider.TicksBelow):
                 y = self.rect().bottom() - z
                 painter.drawLine(x, y, x, y - h)
             x += 10
     opt.subControls = QStyle.SC_SliderGroove
     painter.drawComplexControl(QStyle.CC_Slider, opt)
     for path in self._regions:
         brushcolor = QColor(150, 190, 78, 185) if self._regions.index(path) == self._regionSelected \
             else QColor(237, 242, 255, 185)
         painter.setBrush(brushcolor)
         painter.setPen(Qt.NoPen)
         painter.drawPath(path)
     opt.subControls = QStyle.SC_SliderHandle
     painter.drawComplexControl(QStyle.CC_Slider, opt)
コード例 #4
0
ファイル: videoslider.py プロジェクト: PyQtWorks/vidcutter
 def paintEvent(self, event: QPaintEvent) -> None:
     painter = QStylePainter(self)
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     handle = self.style.subControlRect(self.style.CC_Slider, opt,
                                        self.style.SC_SliderHandle, self)
     interval = self.tickInterval()
     if interval == 0:
         interval = self.pageStep()
     if self.tickPosition() != QSlider.NoTicks:
         for i in range(self.minimum(), self.maximum(), interval):
             x = round((((i - self.minimum()) /
                         (self.maximum() - self.minimum())) *
                        (self.width() - handle.width()) +
                        (handle.width() / 2.0))) - 1
             if i % 500000 == 0:
                 h = 12
                 z = 5
             else:
                 h = 6
                 z = 11
             painter.setPen(QColor('#484640'))
             if self.tickPosition() in (QSlider.TicksBothSides,
                                        QSlider.TicksAbove):
                 y = self.rect().top() + z
                 painter.drawLine(x, y, x, y + h)
             if self.tickPosition() in (QSlider.TicksBothSides,
                                        QSlider.TicksBelow):
                 y = self.rect().bottom() - z
                 painter.drawLine(x, y, x, y - h)
     opt.subControls = QStyle.SC_SliderGroove
     painter.drawComplexControl(QStyle.CC_Slider, opt)
     opt.subControls = QStyle.SC_SliderHandle
     painter.drawComplexControl(QStyle.CC_Slider, opt)
コード例 #5
0
ファイル: videoslider.py プロジェクト: c0re100/vidcutter
 def paintEvent(self, event: QPaintEvent) -> None:
     painter = QStylePainter(self)
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     font = painter.font()
     font.setPixelSize(10)
     painter.setFont(font)
     if self.tickPosition() != QSlider.NoTicks:
         x = 8
         for i in range(self.minimum(), self.width(), 8):
             if i % 5 == 0:
                 h = 18
                 w = 1
                 z = 13
             else:
                 h = 8
                 w = 1
                 z = 23
             tickcolor = '#8F8F8F' if self.theme == 'dark' else '#444'
             pen = QPen(QColor(tickcolor))
             pen.setWidthF(w)
             painter.setPen(pen)
             if self.tickPosition() in (QSlider.TicksBothSides,
                                        QSlider.TicksAbove):
                 y = self.rect().top() + z
                 painter.drawLine(x, y, x, y + h)
             if self.tickPosition() in (QSlider.TicksBothSides,
                                        QSlider.TicksBelow):
                 y = self.rect().bottom() - z
                 painter.drawLine(x, y, x, y - h)
                 if self.parent.mediaAvailable and i % 15 == 0:
                     painter.setPen(Qt.white if self.theme ==
                                    'dark' else Qt.black)
                     timecode = QStyle.sliderValueFromPosition(
                         self.minimum(), self.maximum(), x - self.offset,
                         self.width() - (self.offset * 2))
                     timecode = self.parent.delta2QTime(timecode).toString(
                         self.parent.runtimeformat)
                     painter.drawText(x + 6, y + 6, timecode)
             if x + 30 > self.width():
                 break
             x += 15
     opt.subControls = QStyle.SC_SliderGroove
     painter.drawComplexControl(QStyle.CC_Slider, opt)
     for rect in self._regions:
         rect.setY(int((self.height() - self._regionHeight) / 2) - 8)
         rect.setHeight(self._regionHeight)
         if self._regions.index(rect) == self._regionSelected:
             brushcolor = QColor(150, 190, 78, 185)
         else:
             brushcolor = QColor(237, 242, 255, 185)
         painter.setBrush(brushcolor)
         painter.setPen(QColor(255, 255, 255, 170))
         painter.drawRect(rect)
     opt.subControls = QStyle.SC_SliderHandle
     painter.drawComplexControl(QStyle.CC_Slider, opt)
コード例 #6
0
 def drawHandle(self, painter, handle):
     opt = QStyleOptionSlider()
     self._initStyleOption(opt, handle)
     opt.subControls = QStyle.SC_SliderHandle
     pressed = self.upperPressed
     if handle == QxtSpanSlider.LowerHandle:
         pressed = self.lowerPressed
     if pressed == QStyle.SC_SliderHandle:
         opt.activeSubControls = pressed
         opt.state |= QStyle.State_Sunken
     painter.drawComplexControl(QStyle.CC_Slider, opt)
コード例 #7
0
ファイル: Slider.py プロジェクト: cordsac/stackoverflow
    def paintEvent(self, event):

        p = QPainter(self)
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        opt.subControls = QStyle.SC_SliderGroove
        self.style().drawComplexControl(QStyle.CC_Slider, opt, p, self)

        if self.tickPosition() != QSlider.NoTicks:
            opt.subControls |= QStyle.SC_SliderTickmarks
        opt.subControls = QStyle.SC_SliderHandle
        self.style().drawComplexControl(QStyle.CC_Slider, opt, p, self)
コード例 #8
0
    def drawHandle(self, painter, handle):
        opt = QStyleOptionSlider()
        self._initStyleOption(opt, handle)
        opt.subControls = QStyle.SC_SliderHandle
        pressed = self.upperPressed
        if handle == QxtSpanSlider.LowerHandle:
            pressed = self.lowerPressed

        if pressed == QStyle.SC_SliderHandle:
            opt.activeSubControls = pressed
            opt.state |= QStyle.State_Sunken
        painter.drawComplexControl(QStyle.CC_Slider, opt)
コード例 #9
0
 def copyOptions(self):
     opt = QStyleOptionSlider()
     opt.initFrom(self._slider)
     opt.maximum = self._slider.maximum()
     opt.minimum = self._slider.minimum()
     opt.orientation = self._slider.orientation()
     opt.pageStep = self._slider.pageStep()
     opt.singleStep = self._slider.singleStep()
     return opt
コード例 #10
0
ファイル: guiparts.py プロジェクト: yfukai/cellpose
    def paintEvent(self, event):
        # based on http://qt.gitorious.org/qt/qt/blobs/master/src/gui/widgets/qslider.cpp
        painter = QPainter(self)
        style = QApplication.style()

        for i, value in enumerate([self._low, self._high]):
            opt = QStyleOptionSlider()
            self.initStyleOption(opt)

            # Only draw the groove for the first slider so it doesn't get drawn
            # on top of the existing ones every time
            if i == 0:
                opt.subControls = QStyle.SC_SliderHandle  #QStyle.SC_SliderGroove | QStyle.SC_SliderHandle
            else:
                opt.subControls = QStyle.SC_SliderHandle

            if self.tickPosition() != self.NoTicks:
                opt.subControls |= QStyle.SC_SliderTickmarks

            if self.pressed_control:
                opt.activeSubControls = self.pressed_control
                opt.state |= QStyle.State_Sunken
            else:
                opt.activeSubControls = self.hover_control

            opt.sliderPosition = value
            opt.sliderValue = value
            style.drawComplexControl(QStyle.CC_Slider, opt, painter, self)
コード例 #11
0
ファイル: CColorSlider.py プロジェクト: ArthurFDLR/CubAnimate
    def paintEvent(self, event):
        if not (self._imageRainbow or self._imageAlpha):
            return super(CColorSlider, self).paintEvent(event)

        option = QStyleOptionSlider()
        self.initStyleOption(option)
        # 背景Rect
        groove = self.style().subControlRect(QStyle.CC_Slider, option,
                                             QStyle.SC_SliderGroove, self)
        groove.adjust(3, 5, -3, -5)
        # 滑块Rect
        handle = self.style().subControlRect(QStyle.CC_Slider, option,
                                             QStyle.SC_SliderHandle, self)
        handle.setX(max(min(handle.x(), self.width() - self.height()), 0))
        handle.setWidth(self.height())
        handle.setHeight(self.height())
        radius = self.height() / 2
        painter = QPainter(self)
        painter.setPen(Qt.NoPen)
        painter.drawImage(
            groove,
            self._imageRainbow if self._imageRainbow else self._imageAlpha)

        if not self._imageCircle or not self._imageCircleHover:
            painter.setBrush(
                QColor(245, 245, 245) if option.state
                & QStyle.State_MouseOver else QColor(254, 254, 254))
            painter.drawRoundedRect(handle, radius, radius)
        else:
            painter.drawImage(
                handle, self._imageCircleHover if option.state
                & QStyle.State_MouseOver else self._imageCircle)
コード例 #12
0
ファイル: videoslider.py プロジェクト: c0re100/vidcutter
 def initStyle(self) -> None:
     bground = 'rgba(200, 213, 236, 0.85)' if self._cutStarted else 'transparent'
     height = 60
     handle = 'handle.png'
     handleHeight = 85
     margin = 0
     self._regionHeight = 32
     if self.thumbnailsOn:
         timeline = 'background: transparent url(:images/filmstrip-thumbs.png) repeat-x left;'
     else:
         if self.parent.thumbnailsButton.isChecked():
             timeline = 'background: #000 url(:images/filmstrip.png) repeat-x left;'
         else:
             timeline = 'background: #000 url(:images/filmstrip-nothumbs.png) repeat-x left;'
             handleHeight = 42
         height = 15 if not self.parent.thumbnailsButton.isChecked(
         ) else height
         handle = 'handle-nothumbs.png' if not self.parent.thumbnailsButton.isChecked(
         ) else handle
         self._regionHeight = 32 if self.parent.thumbnailsButton.isChecked(
         ) else 12
     if self._cutStarted:
         _file, _ext = os.path.splitext(handle)
         handle = '%s-select%s' % (_file, _ext)
         opt = QStyleOptionSlider()
         self.initStyleOption(opt)
         control = self.style().subControlRect(QStyle.CC_Slider, opt,
                                               QStyle.SC_SliderHandle, self)
         margin = '%ipx' % control.x()
     self.setStyleSheet(self._styles %
                        (height, height, timeline, bground, height + 2,
                         margin, handle, handleHeight))
コード例 #13
0
ファイル: renderwin.py プロジェクト: jryzkns/qt-touchup
    def __init__(self, loc, img, w, h, r, parent=None):
        super(RenderWin, self).__init__(parent)
        self.parent = parent

        self.setWindowTitle(" ")
        self.setGeometry(loc)

        self.move(parent.x() + parent.width() / 2,
                  parent.y() + parent.height() / 2)

        self.canvas = Canvas(img, w, h, r, self)

        self.scrollview = QScrollArea(self)
        bar_w = self.scrollview.style().subControlRect(
            QStyle.CC_ScrollBar, QStyleOptionSlider(),
            QStyle.SC_ScrollBarGroove, self).x()
        self.scrollview.setWidget(self.canvas)
        self.setCentralWidget(self.scrollview)

        default_max_w, default_max_h = 300, 300
        self.setFixedSize(
            QSize(clip(w + bar_w, 0, default_max_w),
                  clip(h + bar_w, 0, default_max_h)))
        self.setMaximumSize(QSize(w + bar_w, h + bar_w))
        self.canvas.update()
コード例 #14
0
ファイル: guiparts.py プロジェクト: yfukai/cellpose
    def mouseMoveEvent(self, event):
        if self.pressed_control != QStyle.SC_SliderHandle:
            event.ignore()
            return

        event.accept()
        new_pos = self.__pixelPosToRangeValue(self.__pick(event.pos()))
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)

        if self.active_slider < 0:
            offset = new_pos - self.click_offset
            self._high += offset
            self._low += offset
            if self._low < self.minimum():
                diff = self.minimum() - self._low
                self._low += diff
                self._high += diff
            if self._high > self.maximum():
                diff = self.maximum() - self._high
                self._low += diff
                self._high += diff
        elif self.active_slider == 0:
            if new_pos >= self._high:
                new_pos = self._high - 1
            self._low = new_pos
        else:
            if new_pos <= self._low:
                new_pos = self._low + 1
            self._high = new_pos

        self.click_offset = new_pos
        self.update()
コード例 #15
0
    def mousePressEvent(self, ev: QMouseEvent):
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        sr = QRect(self.style().subControlRect(QStyle.CC_Slider, opt,
                                               QStyle.SC_SliderHandle, self))
        self.l_click = False
        if ev.button() == Qt.LeftButton and sr.contains(ev.pos()) is False:

            if (ev.button() == Qt.Vertical):
                n_val = self.minimum() + (
                    (self.maximum() - self.minimum() *
                     (self.height() - ev.y())) / self.height())
            else:
                n_val = self.minimum() + (
                    (self.maximum() - self.minimum()) * ev.x()) / self.width()

            if self.invertedAppearance() is True:
                self.setValue(self.maximum() - n_val)
            else:
                self.setValue(n_val)

            n_val = None
            self.l_click = True
            ev.accept()
        elif ev.button() == Qt.LeftButton:
            self.l_click = True
        else:
            self.l_click = False
コード例 #16
0
 def overlay_rect(self):
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     return self.style().subControlRect(QStyle.CC_ScrollBar,
                                        opt,
                                        QStyle.SC_ScrollBarGroove,
                                        self)
コード例 #17
0
ファイル: QxtSpanSlider.py プロジェクト: wzh201434/simso-gui
    def drawSpan(self, painter, rect):
        opt = QStyleOptionSlider()
        QSlider.initStyleOption(self, opt)

        # area
        groove = self.style().subControlRect(QStyle.CC_Slider, opt,
                                             QStyle.SC_SliderGroove, self)
        if opt.orientation == QtCore.Qt.Horizontal:
            groove.adjust(0, 0, -1, 0)
        else:
            groove.adjust(0, 0, 0, -1)

        # pen & brush
        painter.setPen(QPen(self.gradientLeftColor, 0))
        if opt.orientation == QtCore.Qt.Horizontal:
            self.setupPainter(painter, opt.orientation,
                              groove.center().x(), groove.top(),
                              groove.center().x(), groove.bottom())
        else:
            self.setupPainter(painter, opt.orientation, groove.left(),
                              groove.center().y(), groove.right(),
                              groove.center().y())

        # draw groove
        intersected = QtCore.QRectF(rect.intersected(groove))
        gradient = QLinearGradient(intersected.topLeft(),
                                   intersected.topRight())
        gradient.setColorAt(0, self.gradientLeft)
        gradient.setColorAt(1, self.gradientRight)
        painter.fillRect(intersected, gradient)
コード例 #18
0
 def mousePressEvent(self, event):
     """Add snap-to-location handling."""
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     sr = self.style().subControlRect(QStyle.CC_Slider, opt,
                                      QStyle.SC_SliderHandle, self)
     if (event.button() != Qt.LeftButton or sr.contains(event.pos())):
         super().mousePressEvent(event)
         return
     if self.orientation() == Qt.Vertical:
         half = (0.5 * sr.height()) + 0.5
         max_ = self.height()
         pos = max_ - event.y()
     else:
         half = (0.5 * sr.width()) + 0.5
         max_ = self.width()
         pos = event.x()
     max_ = max_ - 2 * half
     pos = min(max(pos - half, 0), max_) / max_
     val = self.minimum() + (self.maximum() - self.minimum()) * pos
     val = (self.maximum() - val) if self.invertedAppearance() else val
     self.setValue(val)
     event.accept()
     # Process afterward so it's seen as a drag
     super().mousePressEvent(event)
コード例 #19
0
ファイル: MyIntervalSlider.py プロジェクト: n1kolasM/RobotVYE
 def copyOptions(self) :
     opt = QStyleOptionSlider()
     opt.initFrom(self._slider)
     opt.maximum = self._slider.maximum();
     opt.minimum = self._slider.minimum();
     opt.orientation = self._slider.orientation()
     opt.pageStep = self._slider.pageStep()
     opt.singleStep = self._slider.singleStep()
     return opt
コード例 #20
0
    def __init__(self, *args, tip_offset=QPoint(0, -45)):
        super(QSlider, self).__init__(*args)
        self.tip_offset = tip_offset

        self.style = QApplication.style()
        self.opt = QStyleOptionSlider()

        self.valueChanged.connect(self.show_tip)
コード例 #21
0
 def showTooltip(self, value: int) -> None:
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     handle = self.style().subControlRect(QStyle.CC_Slider, opt,
                                          QStyle.SC_SliderHandle, self)
     pos = handle.topLeft()
     pos += self.offset
     globalPos = self.mapToGlobal(pos)
     QToolTip.showText(globalPos, str('{0}%'.format(value)), self)
コード例 #22
0
 def setRestrictValue(self, value: int, force: bool = False) -> None:
     self.restrictValue = value
     if value > 0 or force:
         opt = QStyleOptionSlider()
         self.initStyleOption(opt)
         handle = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle, self)
         self.initStyle(True, '%ipx' % (handle.x() + 5))
     else:
         self.initStyle()
コード例 #23
0
 def mouseMoveEvent(self, event: QMouseEvent) -> None:
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     handle = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle, self)
     if handle.x() <= event.pos().x() <= (handle.x() + handle.width()):
         self.setCursor(self.slider_cursor)
     else:
         self.unsetCursor()
     super(VideoSlider, self).mouseMoveEvent(event)
コード例 #24
0
ファイル: MainWindow.py プロジェクト: DataXujing/kk-music
 def mousePressEvent(self, event):
     # 获取上面的拉动块位置
     option = QStyleOptionSlider()
     self.initStyleOption(option)
     rect = self.style().subControlRect(QStyle.CC_Slider, option,
                                        QStyle.SC_SliderHandle, self)
     if rect.contains(event.pos()):
         # 如果鼠标点击的位置在滑块上则交给Qt自行处理
         super(myQSlider, self).mousePressEvent(event)
         return
コード例 #25
0
    def paintEvent(self, _):
        option = QStyleOptionSlider()
        self.initStyleOption(option)

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

        # 中间圆圈的位置
        rect = self.style().subControlRect(QStyle.CC_Slider, option,
                                           QStyle.SC_SliderHandle, self)

        # 画中间白色线条
        painter.setPen(QPen(Qt.white, 3))
        # painter.setBrush(Qt.red)
        if self.orientation() == Qt.Horizontal:
            y = self.height() / 2
            painter.drawLine(QPointF(0, y), QPointF(self.width(), y))
        else:
            x = self.width() / 2
            painter.drawLine(QPointF(x, 0), QPointF(x, self.height()))
        # 画圆
        painter.setPen(Qt.NoPen)
        if option.state & QStyle.State_MouseOver:  # 双重圆
            # 半透明大圆
            r = rect.height() / 2
            painter.setBrush(QColor(255, 255, 255, 100))
            painter.drawRoundedRect(rect, r, r)
            # 实心小圆(上下左右偏移4)
            rect = rect.adjusted(4, 4, -4, -4)
            r = rect.height() / 2
            painter.setBrush(QColor(255, 255, 255, 255))
            painter.drawRoundedRect(rect, r, r)
            if self.drawtext:
                # 绘制文字
                painter.setPen(QPen(Qt.red, 3))
                width_should_sub = self.get_value_length()
                if self.orientation() == Qt.Horizontal:  # 在上方绘制文字
                    x, y = rect.x() - width_should_sub // 2, rect.y(
                    ) - rect.height() - 4
                else:  # 在左侧绘制文字
                    x, y = rect.x() - rect.width() - 4, rect.y()
                painter.drawText(x, y,
                                 rect.width() + width_should_sub,
                                 rect.height(), Qt.AlignCenter,
                                 str(self.value()))
        else:  # 实心圆
            r = rect.height() / 2
            painter.setBrush(Qt.white)
            painter.drawRoundedRect(rect, r, r)
        self.value_update.emit(self.value(), self.objectName(),
                               self.custom_name)
        if self.show_frame_real_time:
            # 实时更新图像
            self.show_frame.emit()
コード例 #26
0
 def __init__(self, ori, parent=None):
     """Initialize the slider."""
     super().__init__(ori, parent)
     self._opt = QStyleOptionSlider()
     self.initStyleOption(self._opt)
     self._gr = self.style().subControlRect(QStyle.CC_Slider, self._opt,
                                            QStyle.SC_SliderGroove, self)
     self._sr = self.style().subControlRect(QStyle.CC_Slider, self._opt,
                                            QStyle.SC_SliderHandle, self)
     self._precision = 10000
     super().valueChanged.connect(self._convert)
コード例 #27
0
 def showVolumeTip(self, _):
     ''' Volume Slider Tooltip Trick '''
     self.style = self.volumeSlider.style()
     self.opt = QStyleOptionSlider()
     self.volumeSlider.initStyleOption(self.opt)
     rectHandle = self.style.subControlRect(self.style.CC_Slider, self.opt,
                                            self.style.SC_SliderHandle)
     self.tip_offset = QPoint(5, 15)
     pos_local = rectHandle.topLeft() + self.tip_offset
     pos_global = self.volumeSlider.mapToGlobal(pos_local)
     QToolTip.showText(pos_global,
                       str(self.volumeSlider.value()) + " %", self)
コード例 #28
0
ファイル: qrangeslider.py プロジェクト: levidurham/Still
    def mousePressEvent(self, event):
        """Mouse press handler."""
        event.accept()

        style = QApplication.style()
        button = event.button()

        # In a normal slider control, when the user clicks on a point in the
        # slider's total range, but not on the slider part of the control the
        # control would jump the slider value to where the user clicked.
        # For this control, clicks which are not direct hits will slide both
        # slider parts

        if button:
            opt = QStyleOptionSlider()
            self.initStyleOption(opt)

            self.active_slider = -1

            for i, value in enumerate([self._low, self._high]):
                opt.sliderPosition = value
                hit = style.hitTestComplexControl(style.CC_Slider, opt,
                                                  event.pos(), self)
                if hit == style.SC_SliderHandle:
                    self.active_slider = i
                    self.pressed_control = hit

                    self.triggerAction(self.SliderMove)
                    self.setRepeatAction(self.SliderNoAction)
                    self.setSliderDown(True)
                    break

            if self.active_slider < 0:
                self.pressed_control = QStyle.SC_SliderHandle
                self.click_offset = self.__pixelPosToRangeValue(
                    self.__pick(event.pos()))
                self.triggerAction(self.SliderMove)
                self.setRepeatAction(self.SliderNoAction)
        else:
            event.ignore()
コード例 #29
0
    def paintEvent(self, ev):
        if self.min is not None and self.max is not None:
            opt = QStyleOptionSlider()
            self.initStyleOption(opt)

            opt.subControls = QStyle.SC_SliderGroove | QStyle.SC_SliderHandle
            if self.tickPosition() != self.NoTicks:
                opt.subControls |= QStyle.SC_SliderTickmarks

            groove_rect = self.style().subControlRect(QStyle.CC_Slider, opt,
                                                      QStyle.SC_SliderGroove,
                                                      self)

            rect = QRect(groove_rect.left() + self.min * groove_rect.width(),
                         groove_rect.top(),
                         (self.max - self.min) * groove_rect.width(),
                         groove_rect.height())
            painter = QPainter(self)

            painter.fillRect(rect, QBrush(Qt.red))

        super(ColorRangeSlider, self).paintEvent(ev)
コード例 #30
0
ファイル: videoslider.py プロジェクト: PyQtWorks/vidcutter
 def restrictMove(self, value: int) -> None:
     if value < self.restrictValue:
         self.setSliderPosition(self.restrictValue)
     else:
         opt = QStyleOptionSlider()
         self.initStyleOption(opt)
         rectHandle = self.style.subControlRect(self.style.CC_Slider, opt,
                                                self.style.SC_SliderHandle,
                                                self)
         posLocal = rectHandle.topLeft() + QPoint(20, -20)
         posGlobal = self.mapToGlobal(posLocal)
         timerValue = self.parentWidget().timeCounter.text().split(' / ')[0]
         QToolTip.showText(posGlobal, timerValue, self)
コード例 #31
0
    def showMoveTip(self, currentInfo):
        ''' Player Silder Move Tooptip Trick '''
        self.style = self.sliderDuration.style()
        self.opt = QStyleOptionSlider()
        self.sliderDuration.initStyleOption(self.opt)
        rectHandle = self.style.subControlRect(self.style.CC_Slider, self.opt,
                                               self.style.SC_SliderHandle)
        self.tip_offset = QPoint(5, 15)
        pos_local = rectHandle.topLeft() + self.tip_offset
        pos_global = self.sliderDuration.mapToGlobal(pos_local)

        tStr = _seconds_to_time(currentInfo)

        QToolTip.showText(pos_global, tStr, self)
コード例 #32
0
ファイル: CColorSlider.py プロジェクト: ArthurFDLR/CubAnimate
 def mousePressEvent(self, event):
     # 获取上面的拉动块位置
     event.accept()
     option = QStyleOptionSlider()
     self.initStyleOption(option)
     rect = self.style().subControlRect(QStyle.CC_Slider, option,
                                        QStyle.SC_SliderHandle, self)
     rect.setX(max(min(rect.x(), self.width() - self.height()), 0))
     rect.setWidth(self.height())
     rect.setHeight(self.height())
     center = rect.center() - rect.topLeft()
     self.setSliderPosition(
         self.pixelPosToRangeValue(self.pick(event.pos() - center)))
     self.setSliderDown(True)
コード例 #33
0
ファイル: QxtSpanSlider.py プロジェクト: wzh201434/simso-gui
    def mouseMoveEvent(self, event):
        if self.lowerPressed != QStyle.SC_SliderHandle and self.upperPressed != QStyle.SC_SliderHandle:
            event.ignore()
            return

        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        m = self.style().pixelMetric(QStyle.PM_MaximumDragDistance, opt, self)
        newPosition = self.pixelPosToRangeValue(
            self.pick(event.pos()) - self.offset)
        if m >= 0:
            r = self.rect().adjusted(-m, -m, m, m)
            if not r.contains(event.pos()):
                newPosition = self.position

        # pick the preferred handle on the first movement
        if self.firstMovement:
            if self.lower == self.upper:
                if newPosition < self.lowerValue:
                    self.swapControls()
                    self.firstMovement = False
            else:
                self.firstMovement = False

        if self.lowerPressed == QStyle.SC_SliderHandle:
            if self.movement == QxtSpanSlider.NoCrossing:
                newPosition = min(newPosition, self.upper)
            elif self.movement == QxtSpanSlider.NoOverlapping:
                newPosition = min(newPosition, self.upper - 1)

            if (self.movement == QxtSpanSlider.FreeMovement
                    and newPosition > self.upper):
                self.swapControls()
                self.setUpperPosition(newPosition)
            else:
                self.setLowerPosition(newPosition)
        elif self.upperPressed == QStyle.SC_SliderHandle:
            if self.movement == QxtSpanSlider.NoCrossing:
                newPosition = max(newPosition, self.lowerValue)
            elif self.movement == QxtSpanSlider.NoOverlapping:
                newPosition = max(newPosition, self.lowerValue + 1)

            if (self.movement == QxtSpanSlider.FreeMovement
                    and newPosition < self.lower):
                self.swapControls()
                self.setLowerPosition(newPosition)
            else:
                self.setUpperPosition(newPosition)
        event.accept()
コード例 #34
0
ファイル: qxt_span_slider.py プロジェクト: Tinkerforge/brickv
    def paintEvent(self, event):
        painter = QStylePainter(self)

        # ticks
        opt = QStyleOptionSlider()
        self.initStyleOption(opt)
        opt.subControls = QStyle.SC_SliderTickmarks
        painter.drawComplexControl(QStyle.CC_Slider, opt)

        # groove
        opt.sliderPosition = 20
        opt.sliderValue = 0
        opt.subControls = QStyle.SC_SliderGroove
        painter.drawComplexControl(QStyle.CC_Slider, opt)

        # handle rects
        opt.sliderPosition = self.lowerPos
        lr = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle, self)
        lrv = self.pick(lr.center())
        opt.sliderPosition = self.upperPos
        ur = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle, self)
        urv = self.pick(ur.center())

        # span
        minv = min(lrv, urv)
        maxv = max(lrv, urv)
        c = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderGroove, self).center()
        spanRect = QRect(QPoint(c.x() - 2, minv), QPoint(c.x() + 1, maxv))

        if self.orientation() == Qt.Horizontal:
            spanRect = QRect(QPoint(minv, c.y() - 2), QPoint(maxv, c.y() + 1))

        self.drawSpan(painter, spanRect)

        # handles
        if self.lastPressed == QxtSpanSlider.LowerHandle:
            self.drawHandle(painter, QxtSpanSlider.UpperHandle)
            self.drawHandle(painter, QxtSpanSlider.LowerHandle)
        else:
            self.drawHandle(painter, QxtSpanSlider.LowerHandle)
            self.drawHandle(painter, QxtSpanSlider.UpperHandle)