def paintEvent(self, event): painter = QPainter(self) painter.setClipRegion(event.region()) if self.testPaintAttribute(self.BackingStore) and\ self.__data.backingStore is not None: bs = self.__data.backingStore if bs.size() != self.size(): bs = QwtPainter.backingStore(self, self.size()) if self.testAttribute(Qt.WA_StyledBackground): p = QPainter(bs) qwtFillBackground(p, self) self.drawCanvas(p, True) else: p = QPainter() if self.__data.borderRadius <= 0.: # print('**DEBUG: QwtPlotCanvas.paintEvent') QwtPainter.fillPixmap(self, bs) p.begin(bs) self.drawCanvas(p, False) else: p.begin(bs) qwtFillBackground(p, self) self.drawCanvas(p, True) if self.frameWidth() > 0: self.drawBorder(p) p.end() painter.drawPixmap(0, 0, self.__data.backingStore) else: if self.testAttribute(Qt.WA_StyledBackground): if self.testAttribute(Qt.WA_OpaquePaintEvent): qwtFillBackground(painter, self) self.drawCanvas(painter, True) else: self.drawCanvas(painter, False) else: if self.testAttribute(Qt.WA_OpaquePaintEvent): if self.autoFillBackground(): qwtFillBackground(painter, self) qwtDrawBackground(painter, self) else: if self.borderRadius() > 0.: clipPath = QPainterPath() clipPath.addRect(self.rect()) clipPath = clipPath.subtracted( self.borderPath(self.rect())) painter.save() painter.setClipPath(clipPath, Qt.IntersectClip) qwtFillBackground(painter, self) qwtDrawBackground(painter, self) painter.restore() self.drawCanvas(painter, False) if self.frameWidth() > 0: self.drawBorder(painter) if self.hasFocus() and self.focusIndicator( ) == self.CanvasFocusIndicator: self.drawFocusIndicator(painter)
def paintEvent(self, event): painter = QPainter(self) painter.setClipRegion(event.region()) if self.testPaintAttribute(self.BackingStore) and\ self.__data.backingStore is not None: bs = self.__data.backingStore if bs.size() != self.size(): bs = QwtPainter.backingStore(self, self.size()) if self.testAttribute(Qt.WA_StyledBackground): p = QPainter(bs) qwtFillBackground(p, self) self.drawCanvas(p, True) else: p = QPainter() if self.__data.borderRadius <= 0.: # print('**DEBUG: QwtPlotCanvas.paintEvent') QwtPainter.fillPixmap(self, bs) p.begin(bs) self.drawCanvas(p, False) else: p.begin(bs) qwtFillBackground(p, self) self.drawCanvas(p, True) if self.frameWidth() > 0: self.drawBorder(p) p.end() painter.drawPixmap(0, 0, self.__data.backingStore) else: if self.testAttribute(Qt.WA_StyledBackground): if self.testAttribute(Qt.WA_OpaquePaintEvent): qwtFillBackground(painter, self) self.drawCanvas(painter, True) else: self.drawCanvas(painter, False) else: if self.testAttribute(Qt.WA_OpaquePaintEvent): if self.autoFillBackground(): qwtFillBackground(painter, self) qwtDrawBackground(painter, self) else: if self.borderRadius() > 0.: clipPath = QPainterPath() clipPath.addRect(self.rect()) clipPath = clipPath.subtracted(self.borderPath(self.rect())) painter.save() painter.setClipPath(clipPath, Qt.IntersectClip) qwtFillBackground(painter, self) qwtDrawBackground(painter, self) painter.restore() self.drawCanvas(painter, False) if self.frameWidth() > 0: self.drawBorder(painter) if self.hasFocus() and self.focusIndicator() == self.CanvasFocusIndicator: self.drawFocusIndicator(painter)
def drawFrame(self, painter, rect, palette, foregroundRole, frameWidth, midLineWidth, frameStyle): if frameWidth <= 0 or rect.isEmpty(): return shadow = frameStyle & QFrame.Shadow_Mask painter.save() if shadow == QFrame.Plain: outerRect = rect.adjusted(0., 0., -1., -1.) innerRect = outerRect.adjusted( frameWidth, frameWidth, -frameWidth, -frameWidth) path = QPainterPath() path.addRect(outerRect) path.addRect(innerRect) painter.setPen(Qt.NoPen) painter.setBrush(palette.color(foregroundRole)) painter.drawPath(path) else: shape = frameStyle & QFrame.Shape_Mask if shape == QFrame.Box: outerRect = rect.adjusted(0., 0., -1., -1.) midRect1 = outerRect.adjusted( frameWidth, frameWidth, -frameWidth, -frameWidth) midRect2 = midRect1.adjusted( midLineWidth, midLineWidth, -midLineWidth, -midLineWidth) innerRect = midRect2.adjusted( frameWidth, frameWidth, -frameWidth, -frameWidth) path1 = QPainterPath() path1.moveTo(outerRect.bottomLeft()) path1.lineTo(outerRect.topLeft()) path1.lineTo(outerRect.topRight()) path1.lineTo(midRect1.topRight()) path1.lineTo(midRect1.topLeft()) path1.lineTo(midRect1.bottomLeft()) path2 = QPainterPath() path2.moveTo(outerRect.bottomLeft()) path2.lineTo(outerRect.bottomRight()) path2.lineTo(outerRect.topRight()) path2.lineTo(midRect1.topRight()) path2.lineTo(midRect1.bottomRight()) path2.lineTo(midRect1.bottomLeft()) path3 = QPainterPath() path3.moveTo(midRect2.bottomLeft()) path3.lineTo(midRect2.topLeft()) path3.lineTo(midRect2.topRight()) path3.lineTo(innerRect.topRight()) path3.lineTo(innerRect.topLeft()) path3.lineTo(innerRect.bottomLeft()) path4 = QPainterPath() path4.moveTo(midRect2.bottomLeft()) path4.lineTo(midRect2.bottomRight()) path4.lineTo(midRect2.topRight()) path4.lineTo(innerRect.topRight()) path4.lineTo(innerRect.bottomRight()) path4.lineTo(innerRect.bottomLeft()) path5 = QPainterPath() path5.addRect(midRect1) path5.addRect(midRect2) painter.setPen(Qt.NoPen) brush1 = palette.dark().color() brush2 = palette.light().color() if shadow == QFrame.Raised: brush1, brush2 = brush2, brush1 painter.setBrush(brush1) painter.drawPath(path1) painter.drawPath(path4) painter.setBrush(brush2) painter.drawPath(path2) painter.drawPath(path3) painter.setBrush(palette.mid()) painter.drawPath(path5) else: outerRect = rect.adjusted(0., 0., -1., -1.) innerRect = outerRect.adjusted(frameWidth-1., frameWidth-1., -(frameWidth-1.), -(frameWidth-1.)) path1 = QPainterPath() path1.moveTo(outerRect.bottomLeft()) path1.lineTo(outerRect.topLeft()) path1.lineTo(outerRect.topRight()) path1.lineTo(innerRect.topRight()) path1.lineTo(innerRect.topLeft()) path1.lineTo(innerRect.bottomLeft()) path2 = QPainterPath() path2.moveTo(outerRect.bottomLeft()) path2.lineTo(outerRect.bottomRight()) path2.lineTo(outerRect.topRight()) path2.lineTo(innerRect.topRight()) path2.lineTo(innerRect.bottomRight()) path2.lineTo(innerRect.bottomLeft()) painter.setPen(Qt.NoPen) brush1 = palette.dark().color() brush2 = palette.light().color() if shadow == QFrame.Raised: brush1, brush2 = brush2, brush1 painter.setBrush(brush1) painter.drawPath(path1) painter.setBrush(brush2) painter.drawPath(path2) painter.restore()
def drawFrame(self, painter, rect, palette, foregroundRole, frameWidth, midLineWidth, frameStyle): """ Draw a rectangular frame :param QPainter painter: Painter :param QRectF rect: Frame rectangle :param QPalette palette: Palette :param QPalette.ColorRole foregroundRole: Palette :param int frameWidth: Frame width :param int midLineWidth: Used for `QFrame.Box` :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow` """ if frameWidth <= 0 or rect.isEmpty(): return shadow = frameStyle & QFrame.Shadow_Mask painter.save() if shadow == QFrame.Plain: outerRect = rect.adjusted(0., 0., -1., -1.) innerRect = outerRect.adjusted( frameWidth, frameWidth, -frameWidth, -frameWidth) path = QPainterPath() path.addRect(outerRect) path.addRect(innerRect) painter.setPen(Qt.NoPen) painter.setBrush(palette.color(foregroundRole)) painter.drawPath(path) else: shape = frameStyle & QFrame.Shape_Mask if shape == QFrame.Box: outerRect = rect.adjusted(0., 0., -1., -1.) midRect1 = outerRect.adjusted( frameWidth, frameWidth, -frameWidth, -frameWidth) midRect2 = midRect1.adjusted( midLineWidth, midLineWidth, -midLineWidth, -midLineWidth) innerRect = midRect2.adjusted( frameWidth, frameWidth, -frameWidth, -frameWidth) path1 = QPainterPath() path1.moveTo(outerRect.bottomLeft()) path1.lineTo(outerRect.topLeft()) path1.lineTo(outerRect.topRight()) path1.lineTo(midRect1.topRight()) path1.lineTo(midRect1.topLeft()) path1.lineTo(midRect1.bottomLeft()) path2 = QPainterPath() path2.moveTo(outerRect.bottomLeft()) path2.lineTo(outerRect.bottomRight()) path2.lineTo(outerRect.topRight()) path2.lineTo(midRect1.topRight()) path2.lineTo(midRect1.bottomRight()) path2.lineTo(midRect1.bottomLeft()) path3 = QPainterPath() path3.moveTo(midRect2.bottomLeft()) path3.lineTo(midRect2.topLeft()) path3.lineTo(midRect2.topRight()) path3.lineTo(innerRect.topRight()) path3.lineTo(innerRect.topLeft()) path3.lineTo(innerRect.bottomLeft()) path4 = QPainterPath() path4.moveTo(midRect2.bottomLeft()) path4.lineTo(midRect2.bottomRight()) path4.lineTo(midRect2.topRight()) path4.lineTo(innerRect.topRight()) path4.lineTo(innerRect.bottomRight()) path4.lineTo(innerRect.bottomLeft()) path5 = QPainterPath() path5.addRect(midRect1) path5.addRect(midRect2) painter.setPen(Qt.NoPen) brush1 = palette.dark().color() brush2 = palette.light().color() if shadow == QFrame.Raised: brush1, brush2 = brush2, brush1 painter.setBrush(brush1) painter.drawPath(path1) painter.drawPath(path4) painter.setBrush(brush2) painter.drawPath(path2) painter.drawPath(path3) painter.setBrush(palette.mid()) painter.drawPath(path5) else: outerRect = rect.adjusted(0., 0., -1., -1.) innerRect = outerRect.adjusted(frameWidth-1., frameWidth-1., -(frameWidth-1.), -(frameWidth-1.)) path1 = QPainterPath() path1.moveTo(outerRect.bottomLeft()) path1.lineTo(outerRect.topLeft()) path1.lineTo(outerRect.topRight()) path1.lineTo(innerRect.topRight()) path1.lineTo(innerRect.topLeft()) path1.lineTo(innerRect.bottomLeft()) path2 = QPainterPath() path2.moveTo(outerRect.bottomLeft()) path2.lineTo(outerRect.bottomRight()) path2.lineTo(outerRect.topRight()) path2.lineTo(innerRect.topRight()) path2.lineTo(innerRect.bottomRight()) path2.lineTo(innerRect.bottomLeft()) painter.setPen(Qt.NoPen) brush1 = palette.dark().color() brush2 = palette.light().color() if shadow == QFrame.Raised: brush1, brush2 = brush2, brush1 painter.setBrush(brush1) painter.drawPath(path1) painter.setBrush(brush2) painter.drawPath(path2) painter.restore()
def drawFrame(self, painter, rect, palette, foregroundRole, frameWidth, midLineWidth, frameStyle): if frameWidth <= 0 or rect.isEmpty(): return shadow = frameStyle & QFrame.Shadow_Mask painter.save() if shadow == QFrame.Plain: outerRect = rect.adjusted(0., 0., -1., -1.) innerRect = outerRect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth) path = QPainterPath() path.addRect(outerRect) path.addRect(innerRect) painter.setPen(Qt.NoPen) painter.setBrush(palette.color(foregroundRole)) painter.drawPath(path) else: shape = frameStyle & QFrame.Shape_Mask if shape == QFrame.Box: outerRect = rect.adjusted(0., 0., -1., -1.) midRect1 = outerRect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth) midRect2 = midRect1.adjusted(midLineWidth, midLineWidth, -midLineWidth, -midLineWidth) innerRect = midRect2.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth) path1 = QPainterPath() path1.moveTo(outerRect.bottomLeft()) path1.lineTo(outerRect.topLeft()) path1.lineTo(outerRect.topRight()) path1.lineTo(midRect1.topRight()) path1.lineTo(midRect1.topLeft()) path1.lineTo(midRect1.bottomLeft()) path2 = QPainterPath() path2.moveTo(outerRect.bottomLeft()) path2.lineTo(outerRect.bottomRight()) path2.lineTo(outerRect.topRight()) path2.lineTo(midRect1.topRight()) path2.lineTo(midRect1.bottomRight()) path2.lineTo(midRect1.bottomLeft()) path3 = QPainterPath() path3.moveTo(midRect2.bottomLeft()) path3.lineTo(midRect2.topLeft()) path3.lineTo(midRect2.topRight()) path3.lineTo(innerRect.topRight()) path3.lineTo(innerRect.topLeft()) path3.lineTo(innerRect.bottomLeft()) path4 = QPainterPath() path4.moveTo(midRect2.bottomLeft()) path4.lineTo(midRect2.bottomRight()) path4.lineTo(midRect2.topRight()) path4.lineTo(innerRect.topRight()) path4.lineTo(innerRect.bottomRight()) path4.lineTo(innerRect.bottomLeft()) path5 = QPainterPath() path5.addRect(midRect1) path5.addRect(midRect2) painter.setPen(Qt.NoPen) brush1 = palette.dark().color() brush2 = palette.light().color() if shadow == QFrame.Raised: brush1, brush2 = brush2, brush1 painter.setBrush(brush1) painter.drawPath(path1) painter.drawPath(path4) painter.setBrush(brush2) painter.drawPath(path2) painter.drawPath(path3) painter.setBrush(palette.mid()) painter.drawPath(path5) else: outerRect = rect.adjusted(0., 0., -1., -1.) innerRect = outerRect.adjusted(frameWidth - 1., frameWidth - 1., -(frameWidth - 1.), -(frameWidth - 1.)) path1 = QPainterPath() path1.moveTo(outerRect.bottomLeft()) path1.lineTo(outerRect.topLeft()) path1.lineTo(outerRect.topRight()) path1.lineTo(innerRect.topRight()) path1.lineTo(innerRect.topLeft()) path1.lineTo(innerRect.bottomLeft()) path2 = QPainterPath() path2.moveTo(outerRect.bottomLeft()) path2.lineTo(outerRect.bottomRight()) path2.lineTo(outerRect.topRight()) path2.lineTo(innerRect.topRight()) path2.lineTo(innerRect.bottomRight()) path2.lineTo(innerRect.bottomLeft()) painter.setPen(Qt.NoPen) brush1 = palette.dark().color() brush2 = palette.light().color() if shadow == QFrame.Raised: brush1, brush2 = brush2, brush1 painter.setBrush(brush1) painter.drawPath(path1) painter.setBrush(brush2) painter.drawPath(path2) painter.restore()
def drawFrame(self, painter, rect, palette, foregroundRole, frameWidth, midLineWidth, frameStyle): """ Draw a rectangular frame :param QPainter painter: Painter :param QRectF rect: Frame rectangle :param QPalette palette: Palette :param QPalette.ColorRole foregroundRole: Palette :param int frameWidth: Frame width :param int midLineWidth: Used for `QFrame.Box` :param int frameStyle: bitwise OR´ed value of `QFrame.Shape` and `QFrame.Shadow` """ if frameWidth <= 0 or rect.isEmpty(): return shadow = frameStyle & QFrame.Shadow_Mask painter.save() if shadow == QFrame.Plain: outerRect = rect.adjusted(0., 0., -1., -1.) innerRect = outerRect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth) path = QPainterPath() path.addRect(outerRect) path.addRect(innerRect) painter.setPen(Qt.NoPen) painter.setBrush(palette.color(foregroundRole)) painter.drawPath(path) else: shape = frameStyle & QFrame.Shape_Mask if shape == QFrame.Box: outerRect = rect.adjusted(0., 0., -1., -1.) midRect1 = outerRect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth) midRect2 = midRect1.adjusted(midLineWidth, midLineWidth, -midLineWidth, -midLineWidth) innerRect = midRect2.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth) path1 = QPainterPath() path1.moveTo(outerRect.bottomLeft()) path1.lineTo(outerRect.topLeft()) path1.lineTo(outerRect.topRight()) path1.lineTo(midRect1.topRight()) path1.lineTo(midRect1.topLeft()) path1.lineTo(midRect1.bottomLeft()) path2 = QPainterPath() path2.moveTo(outerRect.bottomLeft()) path2.lineTo(outerRect.bottomRight()) path2.lineTo(outerRect.topRight()) path2.lineTo(midRect1.topRight()) path2.lineTo(midRect1.bottomRight()) path2.lineTo(midRect1.bottomLeft()) path3 = QPainterPath() path3.moveTo(midRect2.bottomLeft()) path3.lineTo(midRect2.topLeft()) path3.lineTo(midRect2.topRight()) path3.lineTo(innerRect.topRight()) path3.lineTo(innerRect.topLeft()) path3.lineTo(innerRect.bottomLeft()) path4 = QPainterPath() path4.moveTo(midRect2.bottomLeft()) path4.lineTo(midRect2.bottomRight()) path4.lineTo(midRect2.topRight()) path4.lineTo(innerRect.topRight()) path4.lineTo(innerRect.bottomRight()) path4.lineTo(innerRect.bottomLeft()) path5 = QPainterPath() path5.addRect(midRect1) path5.addRect(midRect2) painter.setPen(Qt.NoPen) brush1 = palette.dark().color() brush2 = palette.light().color() if shadow == QFrame.Raised: brush1, brush2 = brush2, brush1 painter.setBrush(brush1) painter.drawPath(path1) painter.drawPath(path4) painter.setBrush(brush2) painter.drawPath(path2) painter.drawPath(path3) painter.setBrush(palette.mid()) painter.drawPath(path5) else: outerRect = rect.adjusted(0., 0., -1., -1.) innerRect = outerRect.adjusted(frameWidth - 1., frameWidth - 1., -(frameWidth - 1.), -(frameWidth - 1.)) path1 = QPainterPath() path1.moveTo(outerRect.bottomLeft()) path1.lineTo(outerRect.topLeft()) path1.lineTo(outerRect.topRight()) path1.lineTo(innerRect.topRight()) path1.lineTo(innerRect.topLeft()) path1.lineTo(innerRect.bottomLeft()) path2 = QPainterPath() path2.moveTo(outerRect.bottomLeft()) path2.lineTo(outerRect.bottomRight()) path2.lineTo(outerRect.topRight()) path2.lineTo(innerRect.topRight()) path2.lineTo(innerRect.bottomRight()) path2.lineTo(innerRect.bottomLeft()) painter.setPen(Qt.NoPen) brush1 = palette.dark().color() brush2 = palette.light().color() if shadow == QFrame.Raised: brush1, brush2 = brush2, brush1 painter.setBrush(brush1) painter.drawPath(path1) painter.setBrush(brush2) painter.drawPath(path2) painter.restore()