コード例 #1
0
ファイル: plot_canvas.py プロジェクト: 201910835/FingerBeam
 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 QT_MAJOR_VERSION >= 5:
             pixelRatio = bs.devicePixelRatio()
         else:
             pixelRatio = 1.0
         if bs.size() != self.size() * pixelRatio:
             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.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.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)
コード例 #2
0
ファイル: plot_canvas.py プロジェクト: petebachant/python-qwt
    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)
コード例 #3
0
ファイル: plot_canvas.py プロジェクト: 201910835/FingerBeam
def qwtFillBackground(*args):
    if len(args) == 2:
        painter, canvas = args

        rects = []
        if canvas.testAttribute(Qt.WA_StyledBackground):
            recorder = QwtStyleSheetRecorder(canvas.size())
            p = QPainter(recorder)
            qwtDrawStyledBackground(canvas, p)
            p.end()
            if recorder.background.brush.isOpaque():
                rects = recorder.clipRects
            else:
                rects += [canvas.rect()]
        else:
            r = canvas.rect()
            radius = canvas.borderRadius()
            if radius > 0.0:
                sz = QSizeF(radius, radius)
                rects += [
                    QRectF(r.topLeft(), sz),
                    QRectF(r.topRight() - QPointF(radius, 0), sz),
                    QRectF(r.bottomRight() - QPointF(radius, radius), sz),
                    QRectF(r.bottomLeft() - QPointF(0, radius), sz),
                ]

        qwtFillBackground(painter, canvas, rects)

    elif len(args) == 3:
        painter, widget, fillRects = args

        if not fillRects:
            return
        if painter.hasClipping():
            clipRegion = painter.transform().map(painter.clipRegion())
        else:
            clipRegion = widget.contentsRect()
        bgWidget = qwtBackgroundWidget(widget.parentWidget())
        for fillRect in fillRects:
            rect = QRectF(fillRect).toAlignedRect()
            if clipRegion.intersects(rect):
                pm = QPixmap(rect.size())
                QwtPainter.fillPixmap(
                    bgWidget, pm, widget.mapTo(bgWidget, rect.topLeft())
                )
                painter.drawPixmap(rect, pm)

    else:
        raise TypeError(
            "%s() takes 2 or 3 argument(s) (%s given)"
            % ("qwtFillBackground", len(args))
        )
コード例 #4
0
ファイル: plot_canvas.py プロジェクト: petebachant/python-qwt
def qwtFillBackground(*args):
    if len(args) == 2:
        painter, canvas = args

        rects = []
        if canvas.testAttribute(Qt.WA_StyledBackground):
            recorder = QwtStyleSheetRecorder(canvas.size())
            p = QPainter(recorder)
            qwtDrawStyledBackground(canvas, p)
            p.end()
            if recorder.background.brush.isOpaque():
                rects = recorder.clipRects
            else:
                rects += [canvas.rect()]
        else:
            r = canvas.rect()
            radius = canvas.borderRadius()
            if radius > 0.:
                sz = QSizeF(radius, radius)
                rects += [QRectF(r.topLeft(), sz),
                          QRectF(r.topRight()-QPointF(radius, 0), sz),
                          QRectF(r.bottomRight()-QPointF(radius, radius), sz),
                          QRectF(r.bottomLeft()-QPointF(0, radius), sz)]

        qwtFillBackground(painter, canvas, rects)

    elif len(args) == 3:
        painter, widget, fillRects = args
        
        if not fillRects:
            return
        if painter.hasClipping():
            clipRegion = painter.transform().map(painter.clipRegion())
        else:
            clipRegion = widget.contentsRect()
        bgWidget = qwtBackgroundWidget(widget.parentWidget())
        for fillRect in fillRects:
            rect = fillRect.toAlignedRect()
            if clipRegion.intersects(rect):
                pm = QPixmap(rect.size())
                QwtPainter.fillPixmap(bgWidget, pm, widget.mapTo(bgWidget, rect.topLeft()))
                painter.drawPixmap(rect, pm)
        
    else:
        raise TypeError("%s() takes 2 or 3 argument(s) (%s given)"\
                        % ("qwtFillBackground", len(args)))
コード例 #5
0
def qwtDrawBackground(painter, canvas):
    painter.save()
    borderClip = canvas.borderPath(canvas.rect())
    if not borderClip.isEmpty():
        painter.setClipPath(borderClip, Qt.IntersectClip)
    brush = canvas.palette().brush(canvas.backgroundRole())
    if brush.style() == Qt.TexturePattern:
        pm = QPixmap(canvas.size())
        QwtPainter.fillPixmap(canvas, pm)
        painter.drawPixmap(0, 0, pm)
    elif brush.gradient():
        rects = []
        if brush.gradient().coordinateMode() == QGradient.ObjectBoundingMode:
            rects += [canvas.rect()]
        else:
            rects += [painter.clipRegion().boundingRect()]
        useRaster = False
        if painter.paintEngine().type() == QPaintEngine.X11:
            useRaster = True
        if useRaster:
            format_ = QImage.Format_RGB32
            stops = brush.gradient().stops()
            for stop in stops:
                if stop.second.alpha() != 255:
                    format_ = QImage.Format_ARGB32
                    break
            image = QImage(canvas.size(), format_)
            pntr = QPainter(image)
            pntr.setPen(Qt.NoPen)
            pntr.setBrush(brush)
            for rect in rects:
                pntr.drawRect(rect)
            pntr.end()
            painter.drawImage(0, 0, image)
        else:
            painter.setPen(Qt.NoPen)
            painter.setBrush(brush)
            for rect in rects:
                painter.drawRect(rect)
    else:
        painter.setPen(Qt.NoPen)
        painter.setBrush(brush)
        painter.drawRect(painter.clipRegion().boundingRect())

    painter.restore()
コード例 #6
0
ファイル: plot_canvas.py プロジェクト: petebachant/python-qwt
def qwtDrawBackground(painter, canvas):
    painter.save()
    borderClip = canvas.borderPath(canvas.rect())
    if not borderClip.isEmpty():
        painter.setClipPath(borderClip, Qt.IntersectClip)
    brush = canvas.palette().brush(canvas.backgroundRole())
    if brush.style() == Qt.TexturePattern:
        pm = QPixmap(canvas.size())
        QwtPainter.fillPixmap(canvas, pm)
        painter.drawPixmap(0, 0, pm)
    elif brush.gradient():
        rects = []
        if brush.gradient().coordinateMode() == QGradient.ObjectBoundingMode:
            rects += [canvas.rect()]
        else:
            rects += [painter.clipRegion().rects()]
        useRaster = False
        if painter.paintEngine().type() == QPaintEngine.X11:
            useRaster = True
        if useRaster:
            format_ = QImage.Format_RGB32
            stops = brush.gradient().stops()
            for stop in stops:
                if stop.second.alpha() != 255:
                    format_ = QImage.Format_ARGB32
                    break
            image = QImage(canvas.size(), format_)
            p = QPainter(image)
            p.setPen(Qt.NoPen)
            p.setBrush(brush)
            p.drawRects(_rects_conv_PyQt5(rects))
            p.end()
            painter.drawImage(0, 0, image)
        else:
            painter.setPen(Qt.NoPen)
            painter.setBrush(brush)
            painter.drawRects(_rects_conv_PyQt5(rects))
    else:
        painter.setPen(Qt.NoPen)
        painter.setBrush(brush)
        painter.drawRects(_rects_conv_PyQt5(painter.clipRegion().rects()))

    painter.restore()