def drawBorder(self, painter): if self.__data.borderRadius > 0: if self.frameWidth() > 0: QwtPainter.drawRoundedFrame(painter, QRectF(self.frameRect()), self.__data.borderRadius, self.__data.borderRadius, self.palette(), self.frameWidth(), self.frameStyle()) else: if QT_VERSION >= 0x040500: if PYQT5: from qwt.qt.QtGui import QStyleOptionFrame else: from qwt.qt.QtGui import QStyleOptionFrameV3 as\ QStyleOptionFrame opt = QStyleOptionFrame() opt.initFrom(self) frameShape = self.frameStyle() & QFrame.Shape_Mask frameShadow = self.frameStyle() & QFrame.Shadow_Mask opt.frameShape = QFrame.Shape(int(opt.frameShape) | frameShape) if frameShape in (QFrame.Box, QFrame.HLine, QFrame.VLine, QFrame.StyledPanel, QFrame.Panel): opt.lineWidth = self.lineWidth() opt.midLineWidth = self.midLineWidth() else: opt.lineWidth = self.frameWidth() if frameShadow == self.Sunken: opt.state |= QStyle.State_Sunken elif frameShadow == self.Raised: opt.state |= QStyle.State_Raised self.style().drawControl(QStyle.CE_ShapedFrame, opt, painter, self) else: self.drawFrame(painter)
def drawCanvas(self, painter, withBackground): hackStyledBackground = False if withBackground and self.testAttribute(Qt.WA_StyledBackground) and\ self.testPaintAttribute(self.HackStyledBackground): if self.__data.styleSheet.hasBorder and\ not self.__data.styleSheet.borderPath.isEmpty(): hackStyledBackground = True if withBackground: painter.save() if self.testAttribute(Qt.WA_StyledBackground): if hackStyledBackground: painter.setPen(Qt.NoPen) painter.setBrush(self.__data.styleSheet.background.brush) painter.setBrushOrigin( self.__data.styleSheet.background.origin) painter.setClipPath(self.__data.styleSheet.borderPath) painter.drawRect(self.contentsRect()) else: qwtDrawStyledBackground(self, painter) elif self.autoFillBackground(): painter.setPen(Qt.NoPen) painter.setBrush(self.palette().brush(self.backgroundRole())) if self.__data.borderRadius > 0. and self.rect( ) == self.frameRect(): if self.frameWidth() > 0: painter.setClipPath(self.borderPath(self.rect())) painter.drawRect(self.rect()) else: painter.setRenderHint(QPainter.Antialiasing, True) painter.drawPath(self.borderPath(self.rect())) else: painter.drawRect(self.rect()) painter.restore() painter.save() if not self.__data.styleSheet.borderPath.isEmpty(): painter.setClipPath(self.__data.styleSheet.borderPath, Qt.IntersectClip) else: if self.__data.borderRadius > 0.: painter.setClipPath(self.borderPath(self.frameRect()), Qt.IntersectClip) else: # print('**DEBUG: QwtPlotCanvas.drawCanvas') painter.setClipRect(self.contentsRect(), Qt.IntersectClip) self.plot().drawCanvas(painter) painter.restore() if withBackground and hackStyledBackground: opt = QStyleOptionFrame() opt.initFrom(self) self.style().drawPrimitive(QStyle.PE_Frame, opt, painter, self)
def drawCanvas(self, painter, withBackground): hackStyledBackground = False if withBackground and self.testAttribute(Qt.WA_StyledBackground) and\ self.testPaintAttribute(self.HackStyledBackground): if self.__data.styleSheet.hasBorder and\ not self.__data.styleSheet.borderPath.isEmpty(): hackStyledBackground = True if withBackground: painter.save() if self.testAttribute(Qt.WA_StyledBackground): if hackStyledBackground: painter.setPen(Qt.NoPen) painter.setBrush(self.__data.styleSheet.background.brush) painter.setBrushOrigin(self.__data.styleSheet.background.origin) painter.setClipPath(self.__data.styleSheet.borderPath) painter.drawRect(self.contentsRect()) else: qwtDrawStyledBackground(self, painter) elif self.autoFillBackground(): painter.setPen(Qt.NoPen) painter.setBrush(self.palette().brush(self.backgroundRole())) if self.__data.borderRadius > 0. and self.rect() == self.frameRect(): if self.frameWidth() > 0: painter.setClipPath(self.borderPath(self.rect())) painter.drawRect(self.rect()) else: painter.setRenderHint(QPainter.Antialiasing, True) painter.drawPath(self.borderPath(self.rect())) else: painter.drawRect(self.rect()) painter.restore() painter.save() if not self.__data.styleSheet.borderPath.isEmpty(): painter.setClipPath(self.__data.styleSheet.borderPath, Qt.IntersectClip) else: if self.__data.borderRadius > 0.: painter.setClipPath(self.borderPath(self.frameRect()), Qt.IntersectClip) else: # print('**DEBUG: QwtPlotCanvas.drawCanvas') painter.setClipRect(self.contentsRect(), Qt.IntersectClip) self.plot().drawCanvas(painter) painter.restore() if withBackground and hackStyledBackground: opt = QStyleOptionFrame() opt.initFrom(self) self.style().drawPrimitive(QStyle.PE_Frame, opt, painter, self)
def drawBorder(self, painter): if self.__data.borderRadius > 0: if self.frameWidth() > 0: QwtPainter.drawRoundedFrame(painter, QRectF(self.frameRect()), self.__data.borderRadius, self.__data.borderRadius, self.palette(), self.frameWidth(), self.frameStyle()) else: if QT_VERSION >= 0x040500: if PYQT5: from qwt.qt.QtGui import QStyleOptionFrame else: from qwt.qt.QtGui import QStyleOptionFrameV3 as\ QStyleOptionFrame opt = QStyleOptionFrame() opt.initFrom(self) frameShape = self.frameStyle() & QFrame.Shape_Mask frameShadow = self.frameStyle() & QFrame.Shadow_Mask opt.frameShape = QFrame.Shape(int(opt.frameShape)|frameShape) if frameShape in (QFrame.Box, QFrame.HLine, QFrame.VLine, QFrame.StyledPanel, QFrame.Panel): opt.lineWidth = self.lineWidth() opt.midLineWidth = self.midLineWidth() else: opt.lineWidth = self.frameWidth() if frameShadow == self.Sunken: opt.state |= QStyle.State_Sunken elif frameShadow == self.Raised: opt.state |= QStyle.State_Raised self.style().drawControl(QStyle.CE_ShapedFrame, opt, painter, self) else: self.drawFrame(painter)
def drawCanvas(self, painter, withBackground): hackStyledBackground = False if withBackground and self.testAttribute(Qt.WA_StyledBackground) and\ self.testPaintAttribute(self.HackStyledBackground): # Antialiasing rounded borders is done by # inserting pixels with colors between the # border color and the color on the canvas, # When the border is painted before the plot items # these colors are interpolated for the canvas # and the plot items need to be clipped excluding # the anialiased pixels. In situations, where # the plot items fill the area at the rounded # borders this is noticeable. # The only way to avoid these annoying "artefacts" # is to paint the border on top of the plot items. if self.__data.styleSheet.hasBorder and\ not self.__data.styleSheet.borderPath.isEmpty(): # We have a border with at least one rounded corner hackStyledBackground = True if withBackground: painter.save() if self.testAttribute(Qt.WA_StyledBackground): if hackStyledBackground: # paint background without border painter.setPen(Qt.NoPen) painter.setBrush(self.__data.styleSheet.background.brush) painter.setBrushOrigin(self.__data.styleSheet.background.origin) painter.setClipPath(self.__data.styleSheet.borderPath) painter.drawRect(self.contentsRect()) else: qwtDrawStyledBackground(self, painter) elif self.autoFillBackground(): painter.setPen(Qt.NoPen) painter.setBrush(self.palette().brush(self.backgroundRole())) if self.__data.borderRadius > 0. and self.rect() == self.frameRect(): if self.frameWidth() > 0: painter.setClipPath(self.borderPath(self.rect())) painter.drawRect(self.rect()) else: painter.setRenderHint(QPainter.Antialiasing, True) painter.drawPath(self.borderPath(self.rect())) else: painter.drawRect(self.rect()) painter.restore() painter.save() if not self.__data.styleSheet.borderPath.isEmpty(): painter.setClipPath(self.__data.styleSheet.borderPath, Qt.IntersectClip) else: if self.__data.borderRadius > 0.: painter.setClipPath(self.borderPath(self.frameRect()), Qt.IntersectClip) else: # print('**DEBUG: QwtPlotCanvas.drawCanvas') painter.setClipRect(self.contentsRect(), Qt.IntersectClip) self.plot().drawCanvas(painter) painter.restore() if withBackground and hackStyledBackground: # Now paint the border on top opt = QStyleOptionFrame() opt.initFrom(self) self.style().drawPrimitive(QStyle.PE_Frame, opt, painter, self)
def drawCanvas(self, painter, withBackground): hackStyledBackground = False if withBackground and self.testAttribute(Qt.WA_StyledBackground) and\ self.testPaintAttribute(self.HackStyledBackground): # Antialiasing rounded borders is done by # inserting pixels with colors between the # border color and the color on the canvas, # When the border is painted before the plot items # these colors are interpolated for the canvas # and the plot items need to be clipped excluding # the anialiased pixels. In situations, where # the plot items fill the area at the rounded # borders this is noticeable. # The only way to avoid these annoying "artefacts" # is to paint the border on top of the plot items. if self.__data.styleSheet.hasBorder and\ not self.__data.styleSheet.borderPath.isEmpty(): # We have a border with at least one rounded corner hackStyledBackground = True if withBackground: painter.save() if self.testAttribute(Qt.WA_StyledBackground): if hackStyledBackground: # paint background without border painter.setPen(Qt.NoPen) painter.setBrush(self.__data.styleSheet.background.brush) painter.setBrushOrigin( self.__data.styleSheet.background.origin) painter.setClipPath(self.__data.styleSheet.borderPath) painter.drawRect(self.contentsRect()) else: qwtDrawStyledBackground(self, painter) elif self.autoFillBackground(): painter.setPen(Qt.NoPen) painter.setBrush(self.palette().brush(self.backgroundRole())) if self.__data.borderRadius > 0. and self.rect( ) == self.frameRect(): if self.frameWidth() > 0: painter.setClipPath(self.borderPath(self.rect())) painter.drawRect(self.rect()) else: painter.setRenderHint(QPainter.Antialiasing, True) painter.drawPath(self.borderPath(self.rect())) else: painter.drawRect(self.rect()) painter.restore() painter.save() if not self.__data.styleSheet.borderPath.isEmpty(): painter.setClipPath(self.__data.styleSheet.borderPath, Qt.IntersectClip) else: if self.__data.borderRadius > 0.: painter.setClipPath(self.borderPath(self.frameRect()), Qt.IntersectClip) else: # print('**DEBUG: QwtPlotCanvas.drawCanvas') painter.setClipRect(self.contentsRect(), Qt.IntersectClip) self.plot().drawCanvas(painter) painter.restore() if withBackground and hackStyledBackground: # Now paint the border on top opt = QStyleOptionFrame() opt.initFrom(self) self.style().drawPrimitive(QStyle.PE_Frame, opt, painter, self)