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 len(recorder.border.rectList) > 0: return qwtCombinePathList(rect, recorder.border.pathlist) elif self.__data.borderRadius > 0.0: fw2 = self.frameWidth() * 0.5 r = QRectF(rect).adjusted(fw2, fw2, -fw2, -fw2) path = QPainterPath() path.addRoundedRect(r, self.__data.borderRadius, self.__data.borderRadius) return path return QPainterPath()
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 = QRectF(rect).toAlignedRect() widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter, widget) else: brush = widget.palette().brush(widget.backgroundRole()) painter.fillRect(rect, brush)