Пример #1
0
 def paintEvent(self, event):
     opt = QStyleOption()
     opt.initFrom(self)
     opt.state |= (QStyle.State_Sunken
                   if self.isDown() else QStyle.State_Raised)
     p = QStylePainter(self)
     p.drawPrimitive(QStyle.PE_Widget, opt)
Пример #2
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            setting = 'colors.tabs'
            if idx == selected:
                setting += '.selected'
            setting += '.odd' if (idx + 1) % 2 else '.even'

            tab.palette.setColor(QPalette.Window,
                                 config.cache[setting + '.bg'])
            tab.palette.setColor(QPalette.WindowText,
                                 config.cache[setting + '.fg'])

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #3
0
 def paintEvent(self, arg1):
     p = QStylePainter(self)
     opt = QStyleOptionToolButton()
     self.initStyleOption(opt)
     # Disable the menu arrow, since we already got a down arrow icon
     opt.features &= ~QStyleOptionToolButton.HasMenu
     p.drawComplexControl(QStyle.CC_ToolButton, opt)
Пример #4
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        # pylint: disable=bad-config-call
        # WORKAROUND for https://bitbucket.org/logilab/astroid/issue/104
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            bg_parts = ['tabs', 'bg']
            fg_parts = ['tabs', 'fg']
            if idx == selected:
                bg_parts.append('selected')
                fg_parts.append('selected')

            if idx % 2:
                bg_parts.append('odd')
                fg_parts.append('odd')
            else:
                bg_parts.append('even')
                fg_parts.append('even')

            bg_color = config.get('colors', '.'.join(bg_parts))
            fg_color = config.get('colors', '.'.join(fg_parts))
            tab.palette.setColor(QPalette.Window, bg_color)
            tab.palette.setColor(QPalette.WindowText, fg_color)

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #5
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        # pylint: disable=bad-config-call
        # WORKAROUND for https://bitbucket.org/logilab/astroid/issue/104
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            bg_parts = ['tabs', 'bg']
            fg_parts = ['tabs', 'fg']
            if idx == selected:
                bg_parts.append('selected')
                fg_parts.append('selected')

            if idx % 2:
                bg_parts.append('odd')
                fg_parts.append('odd')
            else:
                bg_parts.append('even')
                fg_parts.append('even')

            bg_color = config.get('colors', '.'.join(bg_parts))
            fg_color = config.get('colors', '.'.join(fg_parts))
            tab.palette.setColor(QPalette.Window, bg_color)
            tab.palette.setColor(QPalette.WindowText, fg_color)

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #6
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            # pylint: disable=bad-config-option
            setting = config.val.colors.tabs
            # pylint: enable=bad-config-option
            if idx == selected:
                setting = setting.selected
            setting = setting.odd if (idx + 1) % 2 else setting.even

            tab.palette.setColor(QPalette.Window, setting.bg)
            tab.palette.setColor(QPalette.WindowText, setting.fg)

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #7
0
    def paintEvent(self, event):
        """Override paintEvent to draw the tabs like we want to."""
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            if not event.region().intersects(self.tabRect(idx)):
                # Don't repaint if we are outside the requested region
                continue

            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            setting = 'colors.tabs'
            if idx == selected:
                setting += '.selected'
            setting += '.odd' if (idx + 1) % 2 else '.even'

            tab.palette.setColor(QPalette.Window,
                                 config.cache[setting + '.bg'])
            tab.palette.setColor(QPalette.WindowText,
                                 config.cache[setting + '.fg'])

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #8
0
    def paintEvent(self, event):
        """Override paintEvent to draw the tabs like we want to."""
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            if not event.region().intersects(self.tabRect(idx)):
                # Don't repaint if we are outside the requested region
                continue

            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            setting = 'colors.tabs'
            if self._tab_pinned(idx):
                setting += '.pinned'
            if idx == selected:
                setting += '.selected'
            setting += '.odd' if (idx + 1) % 2 else '.even'

            tab.palette.setColor(QPalette.Window,
                                 config.cache[setting + '.bg'])
            tab.palette.setColor(QPalette.WindowText,
                                 config.cache[setting + '.fg'])

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #9
0
 def paintEvent(self, _e):
     """Override paintEvent to draw the tabs like we want to."""
     p = QStylePainter(self)
     tab = QStyleOptionTab()
     selected = self.currentIndex()
     for idx in range(self.count()):
         self.initStyleOption(tab, idx)
         if idx == selected:
             bg_color = config.get('colors', 'tabs.bg.selected')
             fg_color = config.get('colors', 'tabs.fg.selected')
         elif idx % 2:
             bg_color = config.get('colors', 'tabs.bg.odd')
             fg_color = config.get('colors', 'tabs.fg.odd')
         else:
             bg_color = config.get('colors', 'tabs.bg.even')
             fg_color = config.get('colors', 'tabs.fg.even')
         tab.palette.setColor(QPalette.Window, bg_color)
         tab.palette.setColor(QPalette.WindowText, fg_color)
         indicator_color = self.tabData(idx)
         if indicator_color is None:
             indicator_color = QColor()
         tab.palette.setColor(QPalette.Base, indicator_color)
         if tab.rect.right() < 0 or tab.rect.left() > self.width():
             # Don't bother drawing a tab if the entire tab is outside of
             # the visible tab bar.
             continue
         p.drawControl(QStyle.CE_TabBarTab, tab)
Пример #10
0
 def paintEvent(self, event=None):
     painter = QStylePainter()
     painter.begin(self)
     painter.setOpacity(0.4)
     painter.setBrush(Qt.green)
     painter.drawRect(self.rect())
     self.setGeometry(self.box[0], self.box[1], self.box[2]-self.box[0], self.box[3]-self.box[1])
Пример #11
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            # pylint: disable=bad-config-option
            setting = config.val.colors.tabs
            # pylint: enable=bad-config-option
            if idx == selected:
                setting = setting.selected
            setting = setting.odd if (idx + 1) % 2 else setting.even

            tab.palette.setColor(QPalette.Window, setting.bg)
            tab.palette.setColor(QPalette.WindowText, setting.fg)

            indicator_color = self.tab_indicator_color(idx)
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
 def paintEvent(self, event):
     painter = QStylePainter(self)
     painter.rotate(self.buttonRotation)
     if self.buttonRotation == VerticalRotation.left_side:
         painter.translate(-1 * self.height(), 0)
     elif self.buttonRotation == VerticalRotation.right_side:
         painter.translate(0, -1 * self.width())
     painter.drawControl(QStyle.CE_PushButton, self.getSyleOptions())
Пример #13
0
 def paintEvent(self, event):
     if self.__flat:
         opt = QStyleOptionToolButton()
         self.initStyleOption(opt)
         p = QStylePainter(self)
         p.drawControl(QStyle.CE_ToolButtonLabel, opt)
     else:
         QToolButton.paintEvent(self, event)
Пример #14
0
 def paintEvent(self, event):
     """绘制事件"""
     painter = QStylePainter(self.clazz)
     width = self.clazz.width() / 2
     height = self.clazz.height() / 2
     if self.direction in ("clockwise", "anticlockwise"):
         painter.translate(width, height)    # 设置中心为旋转的中心
         painter.rotate(self.rotate)
         painter.translate(-width, -height)    # 将原点复位
     painter.drawControl(self.getControlElement(), self.getSyleOptions())
Пример #15
0
	def paintEvent(self, event):
		painter = QStylePainter(self)
		option = QStyleOptionTab()

		#painter.begin(self)
		for index in range(self.count()):
			self.initStyleOption(option, index)
			tabRect = self.tabRect(index)
			tabRect.moveLeft(10)
			painter.drawControl(QStyle.CE_TabBarTabShape, option)
			painter.drawText(tabRect, Qt.AlignVCenter | Qt.TextDontClip, self.tabText(index))
Пример #16
0
    def paintEvent(self, event: QtGui.QPaintEvent) -> None:
        if not self.paint:
            return

        sp = QStylePainter(self)
        opt = QStyleOptionToolButton()
        self.initStyleOption(opt)
        opt.state |= (QStyle.State_MouseOver | QStyle.State_AutoRaise
                      | QStyle.State_Raised)  # type: ignore
        opt.activeSubControls |= QStyle.SC_ToolButton  # type: ignore
        sp.drawComplexControl(QStyle.CC_ToolButton, opt)
Пример #17
0
    def paintEvent(self, event):
        painter = QStylePainter(self)
        opt = QStyleOptionTab()

        for i in range(self.count()):
            self.initStyleOption(opt, i)
            key, name = opt.text.split(':')
            if key in self.mColors:
                opt.text = name
                opt.palette.setColor(QPalette.Button, self.mColors[key])
            painter.drawControl(QStyle.CE_TabBarTabShape, opt)
            painter.drawControl(QStyle.CE_TabBarTabLabel, opt)
Пример #18
0
 def paintEvent(self, paintEvent):
     painter = QStylePainter(self)
     painter.drawComplexControl(QStyle.CC_Slider,
                                self._options.getGrooveOptions())
     painter.drawComplexControl(QStyle.CC_Slider,
                                self._options.getLowerHandleOptions())
     painter.drawComplexControl(QStyle.CC_Slider,
                                self._options.getUpperHandleOptions())
Пример #19
0
 def paintEvent(self, event):
     if self.isMenuBar():
         painter = QStylePainter(self)
         option = QStyleOptionToolBar()
         self.initStyleOption(option)
         style = self.style()
         style.drawControl(QStyle.CE_MenuBarEmptyArea, option, painter,
                           self)
     else:
         QToolBar.paintEvent(self, event)
Пример #20
0
 def paintEvent(self, event):
     p = QStylePainter(self)
     p.rotate(90)
     p.translate(0, -self.width())
     opt = QStyleOptionButton()
     opt.initFrom(self)
     opt.text = self.text()
     if self.isChecked():
         opt.state |= QStyle.State_On
     s = opt.rect.size().transposed()
     opt.rect.setSize(s)
     p.drawControl(QStyle.CE_PushButton, opt)
Пример #21
0
    def paintEvent(self, event):
        painter = QStylePainter(self)
        option = QStyleOptionTab()

        for index in range(self.count()):
            self.initStyleOption(option, index)
            tabRect = self.tabRect(index)
            tabRect.moveLeft(5)
            painter.drawControl(QStyle.CE_TabBarTabShape, option)
            painter.drawText(tabRect, Qt.AlignVCenter | Qt.TextDontClip,
                             self.tabText(index))
        painter.end()
Пример #22
0
 def eventFilter(self, obj, event):
     if event.type() != QEvent.Paint or not isinstance(
             obj, QAbstractButton):
         return False
     option: QStyleOptionHeader = QStyleOptionHeader()
     option.initFrom(obj)
     style_state = QStyle.State_None
     if obj.isEnabled():
         style_state |= QStyle.State_Enabled
     if obj.isActiveWindow():
         style_state |= QStyle.State_Active
     if obj.isDown():
         style_state |= QStyle.State_Sunken
     option.state = style_state
     option.rect = obj.rect()
     option.text = obj.text()
     option.position = QStyleOptionHeader.OnlyOneSection
     painter = QStylePainter(obj)
     painter.drawControl(QStyle.CE_Header, option)
     return True
Пример #23
0
    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)
Пример #24
0
 def paintEvent(self, event):
     '''绘制事件'''
     if not self._timer.isActive():
         return super(LinkButton, self).paintEvent(event)
     if self._direction in ("clockwise", "anticlockwise"):
         option = QStyleOptionButton()
         self.initStyleOption(option)
         option.text = ""  # 不让其绘制文字
         painter = QStylePainter(self)
         painter.drawControl(QStyle.CE_PushButton, option)
         # 变换坐标为正中间
         painter.translate(self.rect().center())
         painter.rotate(self._rotate)  # 旋转
         fm = self.fontMetrics()
         # 在变换坐标后的正中间画文字
         w = fm.width(self.text())
         h = fm.height()
         painter.drawText(QRectF(0 - w * 2, 0 - h, w * 2 * 2, h * 2),
                          Qt.AlignCenter, self.text())
         return
     super(LinkButton, self).paintEvent(event)
Пример #25
0
    def paintEvent(self, event):
        opt = QStyleOptionToolButton()
        self.initStyleOption(opt)
        if self.__showMenuIndicator and self.isChecked():
            opt.features |= QStyleOptionToolButton.HasMenu
        if self.__flat:
            # Use default widget background/border styling.
            StyledWidget_paintEvent(self, event)

            p = QStylePainter(self)
            p.drawControl(QStyle.CE_ToolButtonLabel, opt)
        else:
            p = QStylePainter(self)
            p.drawComplexControl(QStyle.CC_ToolButton, opt)
Пример #26
0
 def paintEvent(self, event):
     option = QStyleOption()
     option.initFrom(self)
     painter = QStylePainter(self)
     painter.setRenderHint(QStylePainter.Antialiasing, True)
     painter.drawPrimitive(
         QStyle.PE_Widget if self.testAttribute(Qt.WA_NoSystemBackground)
         else QStyle.PE_Frame, option)
Пример #27
0
    def paintEvent(self, _e):
        """Override paintEvent to draw the tabs like we want to."""
        # pylint: disable=bad-config-call
        # WORKAROUND for https://bitbucket.org/logilab/astroid/issue/104
        p = QStylePainter(self)
        selected = self.currentIndex()
        for idx in range(self.count()):
            tab = QStyleOptionTab()
            self.initStyleOption(tab, idx)

            bg_parts = ["tabs", "bg"]
            fg_parts = ["tabs", "fg"]
            if idx == selected:
                bg_parts.append("selected")
                fg_parts.append("selected")

            if idx % 2:
                bg_parts.append("odd")
                fg_parts.append("odd")
            else:
                bg_parts.append("even")
                fg_parts.append("even")

            bg_color = config.get("colors", ".".join(bg_parts))
            fg_color = config.get("colors", ".".join(fg_parts))
            tab.palette.setColor(QPalette.Window, bg_color)
            tab.palette.setColor(QPalette.WindowText, fg_color)

            try:
                indicator_color = self.tab_data(idx, "indicator-color")
            except KeyError:
                indicator_color = QColor()
            tab.palette.setColor(QPalette.Base, indicator_color)
            if tab.rect.right() < 0 or tab.rect.left() > self.width():
                # Don't bother drawing a tab if the entire tab is outside of
                # the visible tab bar.
                continue
            p.drawControl(QStyle.CE_TabBarTab, tab)
 def paintEvent(self, event):
     p = QStylePainter(self)
     p.rotate(90)
     p.translate(0, - self.width())
     opt = QStyleOptionButton()
     opt.initFrom(self)
     opt.text = self.text()
     if self.isChecked():
         opt.state |= QStyle.State_On
     s = opt.rect.size().transposed()
     opt.rect.setSize(s)
     p.drawControl(QStyle.CE_PushButton, opt)
Пример #29
0
 def paintEvent(self, event):
     QLineEdit.paintEvent(self, event)
     if not self.text() and self.placeholderText() and \
             not self.hasFocus():
         p = QStylePainter(self)
         font = self.font()
         metrics = QFontMetrics(font)
         p.setFont(font)
         color = self.palette().color(QPalette.Mid)
         p.setPen(color)
         left, top, right, bottom = self.getTextMargins()
         contents = self.contentsRect()
         contents = contents.adjusted(left, top, -right, -bottom)
         text = metrics.elidedText(self.placeholderText(),
                                   Qt.ElideMiddle, contents.width())
         p.drawText(contents, Qt.AlignLeft | Qt.AlignVCenter, text)
Пример #30
0
 def paintEvent(self, event):
     p = QStylePainter(self)
     opt = QStyleOptionToolButton()
     self.initStyleOption(opt)
     if self.__text:
         # Replace the text
         opt.text = self.__text
     p.drawComplexControl(QStyle.CC_ToolButton, opt)
     p.end()
Пример #31
0
    def paintEvent(self, e):
        painter = QStylePainter(self)
        painter.setPen(self.palette().color(QPalette.Text))

        opt = QStyleOptionComboBox()
        self.initStyleOption(opt)

        count = self.model().checkedCount()
        if count == 0:
            opt.currentText = self.emptyCheckText
        elif count == 3:
            opt.currentText = self.model().singleCheckText
        else:
            opt.currentText = self.fullCheckText

        painter.drawComplexControl(QStyle.CC_ComboBox, opt)

        painter.drawControl(QStyle.CE_ComboBoxLabel, opt)
Пример #32
0
    def paintEvent(self, event):
        QFrame.paintEvent(self, event)
        text = QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate)
        logicalRect = QRectF(
            QPointF(0, 0),
            QSizeF(QFontMetrics(self.font()).size(Qt.TextSingleLine, text)))
        physicalRect, frameWidth = QRectF(self.rect()), self.frameWidth()
        physicalRect.adjust(frameWidth, frameWidth, -frameWidth, -frameWidth)
        scaleForWidth = physicalRect.width() / logicalRect.width()
        scaleForHeight = physicalRect.height() / logicalRect.height()
        logicalRect.moveTo(frameWidth / scaleForWidth,
                           frameWidth / scaleForHeight)

        painter = QStylePainter(self)
        painter.scale(scaleForWidth, scaleForHeight)
        painter.drawText(logicalRect, Qt.AlignCenter, text)
Пример #33
0
 def paintEvent(self, event):
     painter = QStylePainter(self)
     
     opt = QStyleOptionComboBox()
     self.initStyleOption(opt)
     
     selected = []
     
     for index in range(self.__model.rowCount()):
         item = self.__model.item(index)
         if item.checkState() == Qt.Checked:
             selected.append(item.text())
     
     opt.currentText = " | ".join(selected)
     
     painter.drawComplexControl(QStyle.CC_ComboBox, opt)
     painter.drawControl(QStyle.CE_ComboBoxLabel, opt)
Пример #34
0
    def paintEvent(self, event):
        """Reimplemented."""
        painter = QStylePainter(self)
        option = QStyleOptionComboBox()
        self.initStyleOption(option)
        painter.drawComplexControl(QStyle.CC_ComboBox, option)
        # draw the icon and text
        checked = self.checkedIndices()
        if checked:
            items = [self.itemText(i) for i in checked]
            option.currentText = self.__separator.join(items)
        else:
            option.currentText = self.__placeholderText
            option.palette.setCurrentColorGroup(QPalette.Disabled)

        option.currentIcon = QIcon()
        painter.drawControl(QStyle.CE_ComboBoxLabel, option)
Пример #35
0
 def paintEvent(self, event):
     p = QStylePainter(self)
     q = self.parentWidget()
     if hasFeature(q, QDockWidget.DockWidgetVerticalTitleBar):
         fw = 1 or q.isFloating() and q.style().pixelMetric(
             QStyle.PM_DockWidgetFrameWidth, None, q) or 0
         mw = q.style().pixelMetric(QStyle.PM_DockWidgetTitleMargin, None,
                                    q)
         titleOpt = QStyleOptionDockWidget()
         titleOpt.initFrom(q)
         titleOpt.verticalTitleBar = True
         titleOpt.rect = QRect(
             QPoint(
                 fw, fw + mw + self.collapseButton.size().height() +
                 self.pinButton.size().height()),
             QSize(
                 self.geometry().width() - (fw * 2),
                 self.geometry().height() - (fw * 2) - mw -
                 self.collapseButton.size().height() -
                 self.pinButton.size().height()))
         titleOpt.title = q.windowTitle()
         titleOpt.closable = hasFeature(q, QDockWidget.DockWidgetClosable)
         titleOpt.floatable = hasFeature(q, QDockWidget.DockWidgetFloatable)
         p.drawControl(QStyle.CE_DockWidgetTitle, titleOpt)
     else:
         fw = q.isFloating() and q.style().pixelMetric(
             QStyle.PM_DockWidgetFrameWidth, None, q) or 0
         mw = q.style().pixelMetric(QStyle.PM_DockWidgetTitleMargin, None,
                                    q)
         titleOpt = QStyleOptionDockWidget()
         titleOpt.initFrom(q)
         titleOpt.rect = QRect(
             QPoint(
                 fw + mw + self.collapseButton.size().width() +
                 self.pinButton.size().width(), fw),
             QSize(
                 self.geometry().width() - (fw * 2) - mw -
                 self.collapseButton.size().width() -
                 self.pinButton.size().width(),
                 self.geometry().height() - (fw * 2)))
         titleOpt.title = q.windowTitle()
         titleOpt.closable = hasFeature(q, QDockWidget.DockWidgetClosable)
         titleOpt.floatable = hasFeature(q, QDockWidget.DockWidgetFloatable)
         p.drawControl(QStyle.CE_DockWidgetTitle, titleOpt)
Пример #36
0
    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 paintEvent(self,pe):
     painter=QStylePainter(self)
     pen=QPen(QColor("red"),4)
     painter.setPen(pen)
     painter.drawRect(pe.rect())
Пример #38
0
    def paintEvent(self, event):
        """绘制事件"""
        text = self.text()
        option = QStyleOptionButton()
        self.initStyleOption(option)
        option.text = ''  # 不绘制文字
        painter = QStylePainter(self)
        painter.setRenderHint(QStylePainter.Antialiasing)
        painter.setRenderHint(QStylePainter.HighQualityAntialiasing)
        painter.setRenderHint(QStylePainter.SmoothPixmapTransform)
        painter.drawControl(QStyle.CE_PushButton, option)
        # 变换坐标为正中间
        painter.translate(self.rect().center())
        painter.rotate(self._angle)  # 旋转

        # 绘制图片
        if self._pixmap and not self._pixmap.isNull():
            w = self.width()
            h = self.height()
            pos = QPointF(-self._pixmap.width() / 2,
                          -self._pixmap.height() / 2)
            painter.drawPixmap(pos, self._pixmap)
        elif text:
            # 在变换坐标后的正中间画文字
            fm = self.fontMetrics()
            w = fm.width(text)
            h = fm.height()
            rect = QRectF(0 - w * 2, 0 - h, w * 2 * 2, h * 2)
            painter.drawText(rect, Qt.AlignCenter, text)
        else:
            super(RotateButton, self).paintEvent(event)
Пример #39
0
 def paintEvent(self, event):  # make the widget style aware
     option = QStyleOption()
     option.initFrom(self)
     painter = QStylePainter(self)
     painter.drawPrimitive(QStyle.PE_Widget, option)
Пример #40
0
 def paintEvent(self, event):
     painter = QStylePainter(self)
     option = QStyleOptionToolButton()
     self.initStyleOption(option)
     option.features &= ~QStyleOptionToolButton.HasMenu
     painter.drawComplexControl(QStyle.CC_ToolButton, option)
Пример #41
0
 def paintEvent(self, event):
     painter = QStylePainter(self)
     option = QStyleOptionToolButton()
     self.initStyleOption(option)
     option.icon = self.animation_icons[self.animation_icon_index]
     painter.drawComplexControl(QStyle.CC_ToolButton, option)
Пример #42
0
 def paintEvent(self, event):
     p = QStylePainter(self)
     opt = QStyleOptionFrame()
     opt.initFrom(self)
     p.drawPrimitive(QStyle.PE_PanelTipLabel, opt)
     p.end()
Пример #43
0
 def paintEvent(self, paintEvent):
    painter = QStylePainter(self)
    painter.drawComplexControl(QStyle.CC_Slider, self._options.getGrooveOptions())
    painter.drawComplexControl(QStyle.CC_Slider, self._options.getLowerHandleOptions())
    painter.drawComplexControl(QStyle.CC_Slider, self._options.getUpperHandleOptions())
Пример #44
0
    def paintEvent(self, event):

        if not self.customStyle:
            return QGroupBox.paintEvent(self, event)

        p = QStylePainter(self)
        opt = QStyleOptionGroupBox()
        self.initStyleOption(opt)

        style = qApp.style()
        groupBox = opt

        # // Draw frame
        textRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxLabel)
        checkBoxRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxCheckBox)

        p.save()
        titleRect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxFrame)
        # r.setBottom(style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxContents).top())
        titleRect.setHeight(textRect.height())
        titleRect.moveTop(textRect.top())

        p.setBrush(QBrush(QColor(Qt.blue).lighter(190)))
        p.setPen(Qt.NoPen)
        p.drawRoundedRect(titleRect, 10, 10)
        p.restore()

        if groupBox.subControls & QStyle.SC_GroupBoxFrame:
            frame = QStyleOptionFrame()
            # frame.operator=(groupBox)
            frame.state = groupBox.state
            frame.features = groupBox.features
            frame.lineWidth = groupBox.lineWidth
            frame.midLineWidth = groupBox.midLineWidth
            frame.rect = style.subControlRect(style.CC_GroupBox, opt, style.SC_GroupBoxFrame)
            p.save()
            region = QRegion(groupBox.rect)
            if groupBox.text:
                ltr = groupBox.direction == Qt.LeftToRight
                finalRect = QRect()
                if groupBox.subControls & QStyle.SC_GroupBoxCheckBox:
                    finalRect = checkBoxRect.united(textRect)
                    finalRect.adjust(-4 if ltr else 0, 0, 0 if ltr else 4, 0)
                else:
                    finalRect = textRect

                region -= QRegion(finalRect)

            p.setClipRegion(region)
            style.drawPrimitive(style.PE_FrameGroupBox, frame, p)
            p.restore()

        # // Draw title
        if groupBox.subControls & QStyle.SC_GroupBoxLabel and groupBox.text:
            # textColor = QColor(groupBox.textColor)
            # if textColor.isValid():
            # p.setPen(textColor)
            # alignment = int(groupBox.textAlignment)
            # if not style.styleHint(QStyle.SH_UnderlineShortcut, opt):
            # alignment |= Qt.TextHideMnemonic

            # style.drawItemText(p, textRect,  Qt.TextShowMnemonic | Qt.AlignHCenter | alignment,
            # groupBox.palette, groupBox.state & style.State_Enabled, groupBox.text,
            # QPalette.NoRole if textColor.isValid() else QPalette.WindowText)

            p.save()
            topt = QTextOption(Qt.AlignHCenter | Qt.AlignVCenter)
            f = QFont()
            f.setBold(True)
            p.setFont(f)
            p.setPen(Qt.darkBlue)
            p.drawText(QRectF(titleRect), groupBox.text.replace("&", ""), topt)
            p.restore()

            if groupBox.state & style.State_HasFocus:
                fropt = QStyleOptionFocusRect()
                # fropt.operator=(groupBox)
                fropt.state = groupBox.state
                fropt.rect = textRect
                style.drawPrimitive(style.PE_FrameFocusRect, fropt, p)
Пример #45
0
 def paintEvent(self, event):
     option = QStyleOption()
     option.initFrom(self)
     painter = QStylePainter(self)
     painter.setRenderHint(QStylePainter.Antialiasing, True)
     painter.drawPrimitive(QStyle.PE_Widget if self.testAttribute(Qt.WA_NoSystemBackground) else QStyle.PE_Frame, option)
Пример #46
0
    def paintEvent(self, event):
        option = QStyleOption()
        option.initFrom(self)

        contents_rect = self.style().subElementRect(QStyle.SE_FrameContents, option, self) or self.contentsRect()  # the SE_FrameContents rect is Null unless the stylesheet defines decorations

        if self.graphStyle == self.BarStyle:
            graph_width = self.__dict__['graph_width'] = int(ceil(float(contents_rect.width()) / self.horizontalPixelsPerUnit))
        else:
            graph_width = self.__dict__['graph_width'] = int(ceil(float(contents_rect.width() - 1) / self.horizontalPixelsPerUnit) + 1)

        max_value = self.__dict__['max_value'] = max(chain([0], *(islice(reversed(graph.data), graph_width) for graph in self.graphs if graph.enabled)))

        if self.graphHeight == self.AutomaticHeight or self.graphHeight < 0:
            graph_height = self.__dict__['graph_height'] = max(self.scaler.get_height(max_value), self.minHeight)
        else:
            graph_height = self.__dict__['graph_height'] = max(self.graphHeight, self.minHeight)

        if self.graphStyle == self.BarStyle:
            height_scaling = float(contents_rect.height()) / graph_height
        else:
            height_scaling = float(contents_rect.height() - self.lineThickness) / graph_height

        painter = QStylePainter(self)
        painter.drawPrimitive(QStyle.PE_Widget, option)

        painter.setClipRect(contents_rect)

        painter.save()
        painter.translate(contents_rect.x() + contents_rect.width() - 1, contents_rect.y() + contents_rect.height() - 1)
        painter.scale(-1, -1)

        painter.setRenderHint(QStylePainter.Antialiasing, self.graphStyle != self.BarStyle)

        for graph in (graph for graph in self.graphs if graph.enabled and graph.data):
            if self.boundary is not None and 0 < self.boundary < graph_height:
                boundary_width = min(5.0/height_scaling, self.boundary-0, graph_height-self.boundary)
                pen_color = QLinearGradient(0, (self.boundary - boundary_width) * height_scaling, 0, (self.boundary + boundary_width) * height_scaling)
                pen_color.setColorAt(0, graph.color)
                pen_color.setColorAt(1, graph.over_boundary_color)
                brush_color = QLinearGradient(0, (self.boundary - boundary_width) * height_scaling, 0, (self.boundary + boundary_width) * height_scaling)
                brush_color.setColorAt(0, self.color_with_alpha(graph.color, self.fillTransparency))
                brush_color.setColorAt(1, self.color_with_alpha(graph.over_boundary_color, self.fillTransparency))
            else:
                pen_color = graph.color
                brush_color = self.color_with_alpha(graph.color, self.fillTransparency)
            dataset = islice(reversed(graph.data), graph_width)
            if self.graphStyle == self.BarStyle:
                lines = [QLineF(x*self.horizontalPixelsPerUnit, 0, x*self.horizontalPixelsPerUnit, y*height_scaling) for x, y in enumerate(dataset)]
                painter.setPen(QPen(pen_color, self.lineThickness))
                painter.drawLines(lines)
            else:
                painter.translate(0, +self.lineThickness/2 - 1)

                if self.smoothEnvelope and self.smoothFactor > 0:
                    min_value = 0
                    max_value = graph_height * height_scaling
                    cx_offset = self.horizontalPixelsPerUnit / 3.0
                    smoothness = self.smoothFactor

                    last_values = deque(3*[next(dataset) * height_scaling], maxlen=3)  # last 3 values: 0 last, 1 previous, 2 previous previous

                    envelope = QPainterPath()
                    envelope.moveTo(0, last_values[0])
                    for x, y in enumerate(dataset, 1):
                        x = x * self.horizontalPixelsPerUnit
                        y = y * height_scaling * (1 - smoothness) + last_values[0] * smoothness
                        last_values.appendleft(y)
                        c1x = x - cx_offset * 2
                        c2x = x - cx_offset
                        c1y = limit((1 + smoothness) * last_values[1] - smoothness * last_values[2], min_value, max_value)  # same gradient as previous previous value to previous value
                        c2y = limit((1 - smoothness) * last_values[0] + smoothness * last_values[1], min_value, max_value)  # same gradient as previous value to last value
                        envelope.cubicTo(c1x, c1y, c2x, c2y, x, y)
                else:
                    envelope = QPainterPath()
                    envelope.addPolygon(QPolygonF([QPointF(x*self.horizontalPixelsPerUnit, y*height_scaling) for x, y in enumerate(dataset)]))

                if self.fillEnvelope or graph.fill_envelope:
                    first_element = envelope.elementAt(0)
                    last_element = envelope.elementAt(envelope.elementCount() - 1)
                    fill_path = QPainterPath()
                    fill_path.moveTo(last_element.x, last_element.y)
                    fill_path.lineTo(last_element.x + 1, last_element.y)
                    fill_path.lineTo(last_element.x + 1, -self.lineThickness)
                    fill_path.lineTo(-self.lineThickness, -self.lineThickness)
                    fill_path.lineTo(-self.lineThickness, first_element.y)
                    fill_path.connectPath(envelope)
                    painter.fillPath(fill_path, brush_color)

                painter.strokePath(envelope, QPen(pen_color, self.lineThickness, join=Qt.RoundJoin))

                painter.translate(0, -self.lineThickness/2 + 1)

        if self.boundary is not None and self.boundaryColor:
            painter.setRenderHint(QStylePainter.Antialiasing, False)
            painter.setPen(QPen(self.boundaryColor, 1.0))
            painter.drawLine(0, self.boundary*height_scaling, contents_rect.width(), self.boundary*height_scaling)

        painter.restore()

        # queue the 'updated' signal to be emitted after returning to the main loop
        QMetaObject.invokeMethod(self, 'updated', Qt.QueuedConnection)