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)
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)
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)
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)
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)
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)
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)
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)
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() == QtCore.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)
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)
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)
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)
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)
def paintEvent(self, event): # based on # http://qt.gitorious.org/qt/qt/blobs/master/src/gui/widgets/qslider.cpp painter = QPainter(self) style = self.style() opt = QStyleOptionSlider() self.initStyleOption(opt) groove_rect = style.subControlRect(style.CC_Slider, opt, QStyle.SC_SliderGroove, self) handle_rect = style.subControlRect(style.CC_Slider, opt, QStyle.SC_SliderHandle, self) slider_space = style.pixelMetric(style.PM_SliderSpaceAvailable, opt) range_x = style.sliderPositionFromValue(self.minimum(), self.maximum(), self.value(), slider_space) range_height = 4 groove_rect = QRectF(groove_rect.x(), handle_rect.center().y() - (range_height / 2), groove_rect.width(), range_height) range_rect = QRectF(groove_rect.x(), handle_rect.center().y() - (range_height / 2), range_x, range_height) if style.metaObject().className() != 'QMacStyle': # Paint groove for Fusion and Windows styles cur_brush = painter.brush() cur_pen = painter.pen() painter.setBrush(QBrush(QColor(169, 169, 169))) painter.setPen(Qt.NoPen) # painter.drawRect(groove_rect) painter.drawRoundedRect(groove_rect, groove_rect.height() / 2, groove_rect.height() / 2) painter.setBrush(cur_brush) painter.setPen(cur_pen) cur_brush = painter.brush() cur_pen = painter.pen() painter.setBrush(QBrush(QColor(18, 141, 148))) painter.setPen(Qt.NoPen) painter.drawRect(range_rect) painter.setBrush(cur_brush) painter.setPen(cur_pen) opt = QStyleOptionSlider() self.initStyleOption(opt) opt.subControls = QStyle.SC_SliderHandle if self.tickPosition() != self.NoTicks: opt.subControls |= QStyle.SC_SliderTickmarks if self.isSliderDown(): opt.state |= QStyle.State_Sunken else: opt.state |= QStyle.State_Active opt.activeSubControls = QStyle.SC_None opt.sliderPosition = self.value() opt.sliderValue = self.value() style.drawComplexControl(QStyle.CC_Slider, opt, painter, self)