Esempio n. 1
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()
Esempio 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()
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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()
Esempio n. 6
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()
Esempio n. 7
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)
Esempio n. 8
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)