Example #1
0
 def overlay_rect(self):
     opt = QStyleOptionSlider()
     self.initStyleOption(opt)
     return self.style().subControlRect(QStyle.CC_ScrollBar,
                                        opt,
                                        QStyle.SC_ScrollBarGroove,
                                        self)
Example #2
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)
     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)
Example #3
0
 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)
Example #4
0
 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))
Example #5
0
    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)
Example #6
0
    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()
Example #7
0
    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)
Example #8
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)
Example #9
0
    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()
Example #10
0
    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)
Example #11
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
Example #12
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)
Example #13
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)
Example #14
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
Example #15
0
    def paintEvent(self, event: QPaintEvent) -> None:
        """
        Render the scrollbars using Qt's draw control, and render the frame elements
        dependent on whether the partner horizontal / vertical scrollbar is also visible
        """

        painter = QStylePainter(self)
        if self.orientation() == Qt.Vertical:
            painter.translate(0.0, self.frame_width)
        else:
            painter.translate(self.frame_width, 0.0)

        option = QStyleOptionSlider()
        option.initFrom(self)
        option.maximum = self.maximum()
        option.minimum = self.minimum()
        option.pageStep = self.pageStep()
        option.singleStep = self.singleStep()
        option.sliderPosition = self.sliderPosition()
        option.orientation = self.orientation()
        if self.orientation() == Qt.Horizontal:
            option.state |= QStyle.State_Horizontal

        rect = self.renderRect()

        option.rect = rect
        option.palette = self.palette()
        option.subControls = (
            QStyle.SC_ScrollBarAddLine
            | QStyle.SC_ScrollBarSubLine
            | QStyle.SC_ScrollBarAddPage
            | QStyle.SC_ScrollBarSubPage
            | QStyle.SC_ScrollBarFirst
            | QStyle.SC_ScrollBarLast
        )

        painter.fillRect(
            option.rect, QApplication.palette().window().color().darker(102)
        )
        self.style().drawComplexControl(QStyle.CC_ScrollBar, option, painter)

        # Highlight the handle (slider) on mouse over, otherwise render it as normal
        option.subControls = QStyle.SC_ScrollBarSlider
        if option.state & QStyle.State_MouseOver == QStyle.State_MouseOver:
            palette = self.palette()
            if sys.platform == "win32":
                color = self.palette().base().color()
            else:
                color = self.palette().button().color().lighter(102)
            palette.setColor(QPalette.Button, color)
            option.palette = palette
        self.style().drawComplexControl(QStyle.CC_ScrollBar, option, painter)

        # Render the borders
        painter.resetTransform()
        painter.setPen(self.midPen)
        self.renderEdges(painter)
Example #16
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)
Example #17
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()
Example #18
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)
Example #19
0
 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)
Example #20
0
 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
Example #21
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()
 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)
Example #23
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)
Example #24
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)
Example #25
0
    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)
Example #26
0
 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)
Example #27
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)
Example #28
0
 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)
Example #29
0
    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()
Example #30
0
 def handleMousePress(self, pos, control, value, handle):
     opt = QStyleOptionSlider()
     self._initStyleOption(opt, handle)
     oldControl = control
     control = self.style().hitTestComplexControl(QStyle.CC_Slider, opt, pos, self)
     sr = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle, self)
     if control == QStyle.SC_SliderHandle:
         self.position = value
         self.offset = self.pick(pos - sr.topLeft())
         self.lastPressed = handle
         self.setSliderDown(True)
         self.sliderPressed.emit(handle)
     if control != oldControl:
         self.update(sr)
     return control