Ejemplo n.º 1
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.setClipRegion(event.region())
     opt = QStyleOption()
     opt.initFrom(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
     self.draw(painter)
Ejemplo n.º 2
0
    def borderPath(self, rect):
        """
        Calculate the painter path for a styled or rounded border

        When the canvas has no styled background or rounded borders
        the painter path is empty.

        :param QRect rect: Bounding rectangle of the canvas
        :return: Painter path, that can be used for clipping
        """
        if self.testAttribute(Qt.WA_StyledBackground):
            recorder = QwtStyleSheetRecorder(rect.size())
            painter = QPainter(recorder)
            opt = QStyleOption()
            opt.initFrom(self)
            opt.rect = rect
            self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
            painter.end()
            if not recorder.background.path.isEmpty():
                return recorder.background.path
            if not recorder.border.rectList.isEmpty():
                return qwtCombinePathList(rect, recorder.border.pathlist)
        elif self.__data.borderRadius > 0.:
            fw2 = self.frameWidth() * .5
            r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
            path = QPainterPath()
            path.addRoundedRect(r, self.__data.borderRadius,
                                self.__data.borderRadius)
            return path
        return QPainterPath()
Ejemplo n.º 3
0
    def borderPath(self, rect):
        """
        Calculate the painter path for a styled or rounded border

        When the canvas has no styled background or rounded borders
        the painter path is empty.

        :param QRect rect: Bounding rectangle of the canvas
        :return: Painter path, that can be used for clipping
        """
        if self.testAttribute(Qt.WA_StyledBackground):
            recorder = QwtStyleSheetRecorder(rect.size())
            painter = QPainter(recorder)
            opt = QStyleOption()
            opt.initFrom(self)
            opt.rect = rect
            self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
            painter.end()
            if not recorder.background.path.isEmpty():
                return recorder.background.path
            if not recorder.border.rectList.isEmpty():
                return qwtCombinePathList(rect, recorder.border.pathlist)
        elif self.__data.borderRadius > 0.:
            fw2 = self.frameWidth()*.5
            r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
            path = QPainterPath()
            path.addRoundedRect(r, self.__data.borderRadius,
                                self.__data.borderRadius)
            return path
        return QPainterPath()
Ejemplo n.º 4
0
    def fillPixmap(self, widget, pixmap, offset=None):
        """
        Fill a pixmap with the content of a widget

        In Qt >= 5.0 `QPixmap.fill()` is a nop, in Qt 4.x it is buggy
        for backgrounds with gradients. Thus `fillPixmap()` offers 
        an alternative implementation.
        
        :param QWidget widget: Widget
        :param QPixmap pixmap: Pixmap to be filled
        :param QPoint offset: Offset
        
        .. seealso::
        
            :py:meth:`QPixmap.fill()`
        """
        if offset is None:
            offset = QPoint()
        rect = QRect(offset, pixmap.size())
        painter = QPainter(pixmap)
        painter.translate(-offset)
        autoFillBrush = widget.palette().brush(widget.backgroundRole())
        if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
            bg = widget.palette().brush(QPalette.Window)
            qwtFillRect(widget, painter, rect, bg)
        if widget.autoFillBackground():
            qwtFillRect(widget, painter, rect, autoFillBrush)
        if widget.testAttribute(Qt.WA_StyledBackground):
            painter.setClipRegion(rect)
            opt = QStyleOption()
            opt.initFrom(widget)
            widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter,
                                         widget)
Ejemplo n.º 5
0
    def fillPixmap(self, widget, pixmap, offset=None):
        """
        Fill a pixmap with the content of a widget

        In Qt >= 5.0 `QPixmap.fill()` is a nop, in Qt 4.x it is buggy
        for backgrounds with gradients. Thus `fillPixmap()` offers 
        an alternative implementation.
        
        :param QWidget widget: Widget
        :param QPixmap pixmap: Pixmap to be filled
        :param QPoint offset: Offset
        
        .. seealso::
        
            :py:meth:`QPixmap.fill()`
        """
        if offset is None:
            offset = QPoint()
        rect = QRect(offset, pixmap.size())
        painter = QPainter(pixmap)
        painter.translate(-offset)
        autoFillBrush = widget.palette().brush(widget.backgroundRole())
        if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
            bg = widget.palette().brush(QPalette.Window)
            qwtFillRect(widget, painter, rect, bg)
        if widget.autoFillBackground():
            qwtFillRect(widget, painter, rect, autoFillBrush)
        if widget.testAttribute(Qt.WA_StyledBackground):
            painter.setClipRegion(rect)
            opt = QStyleOption()
            opt.initFrom(widget)
            widget.style().drawPrimitive(QStyle.PE_Widget, opt,
                                         painter, widget)
Ejemplo n.º 6
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.setClipRegion(event.region())
     opt = QStyleOption()
     opt.initFrom(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
     self.draw(painter)
Ejemplo n.º 7
0
 def drawBackground(self, painter, rect, widget):
     if widget.testAttribute(Qt.WA_StyledBackground):
         opt = QStyleOption()
         opt.initFrom(widget)
         opt.rect = rect.toAlignedRect()
         widget.style().drawPrimitive(QStyle.PE_Widget, opt,
                                      painter, widget)
     else:
         brush = widget.palette().brush(widget.backgroundRole())
         painter.fillRect(rect, brush)
Ejemplo n.º 8
0
 def drawBackground(self, painter, rect, widget):
     if widget.testAttribute(Qt.WA_StyledBackground):
         opt = QStyleOption()
         opt.initFrom(widget)
         opt.rect = rect.toAlignedRect()
         widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter,
                                      widget)
     else:
         brush = widget.palette().brush(widget.backgroundRole())
         painter.fillRect(rect, brush)
Ejemplo n.º 9
0
 def fillPixmap(self, widget, pixmap, offset=None):
     if offset is None:
         offset = QPoint()
     rect = QRect(offset, pixmap.size())
     painter = QPainter(pixmap)
     painter.translate(-offset)
     autoFillBrush = widget.palette().brush(widget.backgroundRole())
     if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
         bg = widget.palette().brush(QPalette.Window)
         qwtFillRect(widget, painter, rect, bg)
     if widget.autoFillBackground():
         qwtFillRect(widget, painter, rect, autoFillBrush)
     if widget.testAttribute(Qt.WA_StyledBackground):
         painter.setClipRegion(rect)
         opt = QStyleOption()
         opt.initFrom(widget)
         widget.style().drawPrimitive(QStyle.PE_Widget, opt,
                                      painter, widget)
Ejemplo n.º 10
0
 def fillPixmap(self, widget, pixmap, offset=None):
     if offset is None:
         offset = QPoint()
     rect = QRect(offset, pixmap.size())
     painter = QPainter(pixmap)
     painter.translate(-offset)
     autoFillBrush = widget.palette().brush(widget.backgroundRole())
     if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
         bg = widget.palette().brush(QPalette.Window)
         qwtFillRect(widget, painter, rect, bg)
     if widget.autoFillBackground():
         qwtFillRect(widget, painter, rect, autoFillBrush)
     if widget.testAttribute(Qt.WA_StyledBackground):
         painter.setClipRegion(rect)
         opt = QStyleOption()
         opt.initFrom(widget)
         widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter,
                                      widget)
Ejemplo n.º 11
0
 def updateStyleSheetInfo(self):
     if not self.testAttribute(Qt.WA_StyledBackground):
         return
     recorder = QwtStyleSheetRecorder(self.size())
     painter = QPainter(recorder)
     opt = QStyleOption()
     opt.initFrom(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
     painter.end()
     self.__data.styleSheet.hasBorder = not recorder.border.rectList.isEmpty()
     self.__data.styleSheet.cornerRects = recorder.clipRects
     if recorder.background.path.isEmpty():
         if not recorder.border.rectList.isEmpty():
             self.__data.styleSheet.borderPath =\
                 qwtCombinePathList(self.rect(), recorder.border.pathlist)
     else:
         self.__data.styleSheet.borderPath = recorder.background.path
         self.__data.styleSheet.background.brush = recorder.background.brush
         self.__data.styleSheet.background.origin = recorder.background.origin
Ejemplo n.º 12
0
 def updateStyleSheetInfo(self):
     if not self.testAttribute(Qt.WA_StyledBackground):
         return
     recorder = QwtStyleSheetRecorder(self.size())
     painter = QPainter(recorder)
     opt = QStyleOption()
     opt.initFrom(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
     painter.end()
     self.__data.styleSheet.hasBorder = not recorder.border.rectList.isEmpty(
     )
     self.__data.styleSheet.cornerRects = recorder.clipRects
     if recorder.background.path.isEmpty():
         if not recorder.border.rectList.isEmpty():
             self.__data.styleSheet.borderPath =\
                 qwtCombinePathList(self.rect(), recorder.border.pathlist)
     else:
         self.__data.styleSheet.borderPath = recorder.background.path
         self.__data.styleSheet.background.brush = recorder.background.brush
         self.__data.styleSheet.background.origin = recorder.background.origin
Ejemplo n.º 13
0
 def borderPath(self, rect):
     if self.testAttribute(Qt.WA_StyledBackground):
         recorder = QwtStyleSheetRecorder(rect.size())
         painter = QPainter(recorder)
         opt = QStyleOption()
         opt.initFrom(self)
         opt.rect = rect
         self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
         painter.end()
         if not recorder.background.path.isEmpty():
             return recorder.background.path
         if not recorder.border.rectList.isEmpty():
             return qwtCombinePathList(rect, recorder.border.pathlist)
     elif self.__data.borderRadius > 0.:
         fw2 = self.frameWidth()*.5
         r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
         path = QPainterPath()
         path.addRoundedRect(r, self.__data.borderRadius,
                             self.__data.borderRadius)
         return path
     return QPainterPath()
Ejemplo n.º 14
0
 def borderPath(self, rect):
     if self.testAttribute(Qt.WA_StyledBackground):
         recorder = QwtStyleSheetRecorder(rect.size())
         painter = QPainter(recorder)
         opt = QStyleOption()
         opt.initFrom(self)
         opt.rect = rect
         self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
         painter.end()
         if not recorder.background.path.isEmpty():
             return recorder.background.path
         if not recorder.border.rectList.isEmpty():
             return qwtCombinePathList(rect, recorder.border.pathlist)
     elif self.__data.borderRadius > 0.:
         fw2 = self.frameWidth() * .5
         r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2)
         path = QPainterPath()
         path.addRoundedRect(r, self.__data.borderRadius,
                             self.__data.borderRadius)
         return path
     return QPainterPath()
Ejemplo n.º 15
0
 def drawBackground(self, painter, rect, widget):
     """
     Fill rect with the background of a widget
     
     :param QPainter painter: Painter
     :param QRectF rect: Rectangle to be filled
     :param QWidget widget: Widget
     
     .. seealso::
     
         :py:data:`QStyle.PE_Widget`, :py:meth:`QWidget.backgroundRole()`
     """
     if widget.testAttribute(Qt.WA_StyledBackground):
         opt = QStyleOption()
         opt.initFrom(widget)
         opt.rect = rect.toAlignedRect()
         widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter,
                                      widget)
     else:
         brush = widget.palette().brush(widget.backgroundRole())
         painter.fillRect(rect, brush)
Ejemplo n.º 16
0
 def drawBackground(self, painter, rect, widget):
     """
     Fill rect with the background of a widget
     
     :param QPainter painter: Painter
     :param QRectF rect: Rectangle to be filled
     :param QWidget widget: Widget
     
     .. seealso::
     
         :py:data:`QStyle.PE_Widget`, :py:meth:`QWidget.backgroundRole()`
     """
     if widget.testAttribute(Qt.WA_StyledBackground):
         opt = QStyleOption()
         opt.initFrom(widget)
         opt.rect = rect.toAlignedRect()
         widget.style().drawPrimitive(QStyle.PE_Widget, opt,
                                      painter, widget)
     else:
         brush = widget.palette().brush(widget.backgroundRole())
         painter.fillRect(rect, brush)
Ejemplo n.º 17
0
def qwtDrawStyledBackground(w, painter):
    opt = QStyleOption()
    opt.initFrom(w)
    w.style().drawPrimitive(QStyle.PE_Widget, opt, painter, w)
Ejemplo n.º 18
0
def buttonShift(w):
    option = QStyleOption()
    option.initFrom(w)
    ph = w.style().pixelMetric(QStyle.PM_ButtonShiftHorizontal, option, w)
    pv = w.style().pixelMetric(QStyle.PM_ButtonShiftVertical, option, w)
    return QSize(ph, pv)
Ejemplo n.º 19
0
def qwtDrawStyledBackground(w, painter):
    opt = QStyleOption()
    opt.initFrom(w)
    w.style().drawPrimitive(QStyle.PE_Widget, opt, painter, w)
Ejemplo n.º 20
0
def buttonShift(w):
    option = QStyleOption()
    option.initFrom(w)
    ph = w.style().pixelMetric(QStyle.PM_ButtonShiftHorizontal, option, w)
    pv = w.style().pixelMetric(QStyle.PM_ButtonShiftVertical, option, w)
    return QSize(ph, pv)