Пример #1
0
 def paintEvent(self, event):
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     # 反锯齿
     painter.setRenderHint(QPainter.Antialiasing)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
Пример #2
0
def StyledWidget_paintEvent(self, event):
    """A default styled QWidget subclass  paintEvent function.
    """
    opt = QStyleOption()
    opt.initFrom(self)
    painter = QPainter(self)
    self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
Пример #3
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)
Пример #4
0
 def paintEvent(self, event):
     """解决继承的QWidget qss无效"""
     super(BallWidget, self).paintEvent(event)
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
Пример #5
0
def pixmap(name, size, mode, state):
    """Returns a (possibly cached) pixmap of the name and size with the default text color.
    
    The state argument is ignored for now.
    
    """
    if mode == QIcon.Selected:
        color = QApplication.palette().highlightedText().color()
    else:
        color = QApplication.palette().text().color()
    key = (name, size.width(), size.height(), color.rgb(), mode)
    try:
        return _pixmaps[key]
    except KeyError:
        i = QImage(size, QImage.Format_ARGB32_Premultiplied)
        i.fill(0)
        painter = QPainter(i)
        # render SVG symbol
        QSvgRenderer(os.path.join(__path__[0], name + ".svg")).render(painter)
        # recolor to text color
        painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
        painter.fillRect(i.rect(), color)
        painter.end()
        # let style alter the drawing based on mode, and create QPixmap
        pixmap = QApplication.style().generatedIconPixmap(
            mode, QPixmap.fromImage(i), QStyleOption())
        _pixmaps[key] = pixmap
        return pixmap
Пример #6
0
    def paintEvent(self, event):
        option = QStyleOption()
        option.initFrom(self)

        h = option.rect.height()
        w = option.rect.width()
        if self.m_shape in (QLed.Triangle, QLed.Round):
            aspect = (4 / 3.0) if self.m_shape == QLed.Triangle else 2.0
            ah = w / aspect
            aw = w
            if ah > h:
                ah = h
                aw = h * aspect
            x = abs(aw - w) / 2.0
            y = abs(ah - h) / 2.0
            bounds = QRectF(x, y, aw, ah)
        else:
            size = min(w, h)
            x = abs(size - w) / 2.0
            y = abs(size - h) / 2.0
            bounds = QRectF(x, y, size, size)

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

        (dark_r, dark_g, dark_b) = self.colours[self.m_onColour if self.
                                                m_value else self.m_offColour]

        dark_str = "rgb(%d,%d,%d)" % (dark_r, dark_g, dark_b)
        light_str = "rgb(%d,%d,%d)" % self.adjust(dark_r, dark_g, dark_b)

        shape = self.shapes[self.m_shape] % (dark_str, light_str)
        shape = shape.encode('utf-8')
        self.renderer.load(QByteArray(shape))
        self.renderer.render(painter, bounds)
Пример #7
0
def drawIndicatorIcon(palette, style):
    pix = QPixmap(14, 14)
    pix.fill(Qt.transparent)
    branchOption = QStyleOption()
    #r = QRect(QPoint(0, 0), pix.size())
    branchOption.rect = QRect(2, 2, 9, 9) ## ### hardcoded in qcommonstyle.cpp
    branchOption.palette = palette
    branchOption.state = QStyle.State_Children

    p = QPainter()
    ## Draw closed state
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()
    rc = QIcon(pix)
    rc.addPixmap(pix, QIcon.Selected, QIcon.Off)
    ## Draw opened state
    branchOption.state |= QStyle.State_Open
    pix.fill(Qt.transparent)
    p.begin(pix)
    style.drawPrimitive(QStyle.PE_IndicatorBranch, branchOption, p)
    p.end()

    rc.addPixmap(pix, QIcon.Normal, QIcon.On)
    rc.addPixmap(pix, QIcon.Selected, QIcon.On)
    return rc
Пример #8
0
 def paintEvent(self, event):
     "Reimplementation of paintEvent to allow for style sheets"
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
     painter.end()
Пример #9
0
 def paintEvent(self, event):
     # 解决QSS问题
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, option, painter, self)
     super(CustomPaintWidget, self).paintEvent(event)
Пример #10
0
 def paintEvent(self, event):
     """由于继承的问题会导致子控件QWidget无法通过QSS设置样式,需要重写该方法"""
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, option, painter, self)
     QWidget.paintEvent(self, event)
Пример #11
0
    def paintEvent(self, _):
        opt = QStyleOption()
        opt.initFrom(self)
        painter = QPainter(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)

        if self.show_pieces:
            if len(self.pieces) == 0:  # Nothing to paint
                return

            if len(self.pieces) <= self.width():  # We have less pieces than pixels
                piece_width = self.width() / float(len(self.pieces))
                for i in range(len(self.pieces)):
                    if self.pieces[i]:
                        painter.fillRect(
                            QRect(float(i) * piece_width, 0, math.ceil(piece_width), self.height()), QColor(230, 115, 0)
                        )
            else:  # We have more pieces than pixels, group pieces
                pieces_per_pixel = len(self.pieces) / float(self.width())
                for i in range(self.width()):
                    begin_piece = int(pieces_per_pixel * i)
                    end_piece = int(begin_piece + pieces_per_pixel)
                    piece_sum = 0
                    for j in range(begin_piece, end_piece):
                        piece_sum += self.pieces[j]
                    qt_color = QColor()
                    qt_color.setHsl(26, 255, 128 + 127 * (1 - piece_sum / pieces_per_pixel))
                    painter.fillRect(QRect(i, 0, 10, self.height()), qt_color)
        else:
            painter.fillRect(QRect(0, 0, self.width() * self.fraction, self.height()), QColor(230, 115, 0))
Пример #12
0
 def paintEvent(self, event):
     '''
     避免多重传值后的功能失效,从而可以继续使用qss设置样式
     '''
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
Пример #13
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)
Пример #14
0
 def paintEvent(self, event):
     painter = QPainter(self)
     option = QStyleOption()
     option.rect = self.rect()
     option.state = QStyle.State_Horizontal
     option.palette = self.palette()
     self.style().drawPrimitive(QStyle.PE_IndicatorToolBarSeparator, option,
                                painter, self)
Пример #15
0
 def getSyleOptions(self):
     options = QStyleOption()
     options.initFrom(self.clazz)
     size = options.rect.size()
     size.transpose()
     options.rect.setSize(size)
     options.features = QStyleOption.SO_Default
     return options
Пример #16
0
 def paintEvent(self, event):
     '''
     Birden çok değer aktarımından sonra işlev arızasını önlemek için, stili ayarlamak için qss kullanmaya devam edebilirsiniz.
     '''
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
Пример #17
0
 def paintEvent(self, event):
     #Subclasses from QWidget loses their ability to use StyleSheets
     #In order to use the StyleSheets you need to provide a paintEvent to the custom widget.
     #This part of code is based on https://stackoverflow.com/questions/2565963/pyqt4-qwidget-subclass-not-responding-to-new-setstylesheet-background-colour
     opt = QStyleOption()
     #opt.init(self)
     opt.initFrom(self)
     painter = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
Пример #18
0
    def paintEvent(self, event):
        painter = QPainter(self)
        pixmap = QPixmap().fromImage(self._bgImage, Qt.AutoColor)
        painter.drawPixmap(self.rect(), pixmap)

        opt = QStyleOption()
        opt.initFrom(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
        super().paintEvent(event)
Пример #19
0
 def paintEvent(self, event):
     '''无边框透明后圆角问题'''
     super(FramelessWindow, self).paintEvent(event)
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.setPen(QPen(QColor(0, 0, 0, 1), 2 * self.margin))
     painter.drawRect(self.rect())
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
Пример #20
0
 def paintEvent(self, paintEvent):
     """
     This is needed for the widget to pick the stylesheet.
     :type paintEvent: QPaintEvent
     """
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Widget, option, painter, self)
Пример #21
0
 def paintEvent(self, pe):
     """
     @Overrides default QWidget method
     :param pe:
     :return:
     """
     o = QStyleOption()
     o.initFrom(self)
     p = QPainter(self)
     self.style().drawPrimitive(QStyle.PE_Widget, o, p, self)
Пример #22
0
 def paintEvent(self, event):
     super(EditorBase, self).paintEvent(event)
     opt = QStyleOption()
     opt.initFrom(self)
     c = opt.palette.color(QPalette.Window)
     # this should allow changing color directly too
     # as well as saving recoloring when it's already colored
     if self._stylebackgroundColor != c.name():
         self.set_background_color(c.name())
         self.setMarginsBackgroundColor(c.darker(110))
         self._stylebackgroundColor = c.name()
Пример #23
0
 def paintEvent(self, paint_event: QPaintEvent):
     """
     Override painEvent in order to support stylesheets.
     :param paint_event:
     :return:
     """
     style_option = QStyleOption()
     style_option.initFrom(self)
     painter = QPainter(self)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Widget, style_option, painter, self)
Пример #24
0
 def paintEvent(self, event):
     QToolButton.paintEvent(self, event)
     painter = QPainter(self)
     opt = QStyleOption()
     opt.initFrom(self)
     opt.rect = QRect(6, self.rect().center().y() - 3, 8, 8)
     opt.rect.translate(0, -3)
     style = self.style()
     style.drawPrimitive(QStyle.PE_IndicatorArrowUp, opt, painter, self)
     opt.rect.translate(0, 6)
     style.drawPrimitive(QStyle.PE_IndicatorArrowDown, opt, painter, self)
Пример #25
0
 def paintEvent(self, event):
     """
     self is derived from QWidget, Stylesheets don't work unless \
     paintEvent is reimplemented.y
     at the same time, if self is derived from QFrame, this isn't needed.
     """
     option = QStyleOption()
     option.initFrom(self)
     painter = QPainter(self)
     style = self.style()
     style.drawPrimitive(QStyle.PE_Widget, option, painter, self)
Пример #26
0
 def drawPrimitive(self, element, option, paintery, widget=None):
     if element == self.PE_IndicatorItemViewItemDrop and not option.rect.isNull(
     ):
         optionNew = QStyleOption(option)
         optionNew.rect.setLeft(0)
         # optionNew.rect.setTop(0)
         if widget:
             optionNew.rect.setRight(widget.width())
         option = optionNew
     paintery.setPen(QColor("#262525"))
     super().drawPrimitive(element, option, paintery, widget)
Пример #27
0
    def paintEvent(self, paint_event: QPaintEvent):
        if self.p:
            painter = QPainter(self)
            painter.setRenderHint(QPainter.SmoothPixmapTransform)
            painter.drawPixmap(self.rect(), self.p)

        # Support stylesheets
        style_option = QStyleOption()
        style_option.initFrom(self)
        painter = QPainter(self)
        style = self.style()
        style.drawPrimitive(QStyle.PE_Widget, style_option, painter, self)
Пример #28
0
    def paintEvent(self, event):
        """ Метод переопределён для корректной работы стилей
        для класса Task, унаследованного от QWidget
        Args:
            event: событие
        """

        opt = QStyleOption()
        opt.initFrom(self)
        qp = QPainter(self)
        style = self.style()
        style.drawPrimitive(QStyle.PE_Widget, opt, qp, self)
Пример #29
0
 def paintEvent(self, event):
     """
     重写paintEvent 否则不能使用样式表定义外观
     :param evt:
     :return:
     """
     opt = QStyleOption()
     opt.initFrom(self)
     painter = QPainter(self)
     # 反锯齿
     painter.setRenderHint(QPainter.Antialiasing)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
Пример #30
0
    def paintEvent(self, paint_event):
        """
        A simple override to the `QWidget.paintEvent` required soo the QSS
        rules have effect over `QWidget` subclasses.

        From: http://doc.qt.io/qt-5/stylesheet-reference.html#qwidget-widget

        :type paint_event: PyQt5.QtGui.QPaintEvent
        """
        opt = QStyleOption()
        opt.initFrom(self)
        p = QPainter(self)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, p, self)