Пример #1
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.setClipRegion(event.region())
     opt = QStyleOption()
     opt.initFrom(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
     self.draw(painter)
Пример #2
0
 def paintEvent(self, event):
     painter = QPainter(self)
     painter.setClipRegion(event.region())
     opt = QStyleOption()
     opt.initFrom(self)
     self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)
     self.draw(painter)
Пример #3
0
    def fillPixmap(self, widget, pixmap, offset=None):
        """
        Fill a pixmap with the content of a widget

        In Qt >= 5.0 `QPixmap.fill()` is a nop, in Qt 4.x it is buggy
        for backgrounds with gradients. Thus `fillPixmap()` offers 
        an alternative implementation.
        
        :param QWidget widget: Widget
        :param QPixmap pixmap: Pixmap to be filled
        :param QPoint offset: Offset
        
        .. seealso::
        
            :py:meth:`QPixmap.fill()`
        """
        if offset is None:
            offset = QPoint()
        rect = QRect(offset, pixmap.size())
        painter = QPainter(pixmap)
        painter.translate(-offset)
        autoFillBrush = widget.palette().brush(widget.backgroundRole())
        if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
            bg = widget.palette().brush(QPalette.Window)
            qwtFillRect(widget, painter, rect, bg)
        if widget.autoFillBackground():
            qwtFillRect(widget, painter, rect, autoFillBrush)
        if widget.testAttribute(Qt.WA_StyledBackground):
            painter.setClipRegion(rect)
            opt = QStyleOption()
            opt.initFrom(widget)
            widget.style().drawPrimitive(QStyle.PE_Widget, opt,
                                         painter, widget)
Пример #4
0
    def fillPixmap(self, widget, pixmap, offset=None):
        """
        Fill a pixmap with the content of a widget

        In Qt >= 5.0 `QPixmap.fill()` is a nop, in Qt 4.x it is buggy
        for backgrounds with gradients. Thus `fillPixmap()` offers 
        an alternative implementation.
        
        :param QWidget widget: Widget
        :param QPixmap pixmap: Pixmap to be filled
        :param QPoint offset: Offset
        
        .. seealso::
        
            :py:meth:`QPixmap.fill()`
        """
        if offset is None:
            offset = QPoint()
        rect = QRect(offset, pixmap.size())
        painter = QPainter(pixmap)
        painter.translate(-offset)
        autoFillBrush = widget.palette().brush(widget.backgroundRole())
        if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
            bg = widget.palette().brush(QPalette.Window)
            qwtFillRect(widget, painter, rect, bg)
        if widget.autoFillBackground():
            qwtFillRect(widget, painter, rect, autoFillBrush)
        if widget.testAttribute(Qt.WA_StyledBackground):
            painter.setClipRegion(rect)
            opt = QStyleOption()
            opt.initFrom(widget)
            widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter,
                                         widget)
Пример #5
0
 def paintEvent(self, event):
     painter = QPainter(self)
     if not self.contentsRect().contains(event.rect()):
         painter.save()
         painter.setClipRegion(event.region() & self.frameRect())
         self.drawFrame(painter)
         painter.restore()
     painter.setClipRegion(event.region() & self.contentsRect())
     self.drawContents(painter)
Пример #6
0
 def paintEvent(self, event):
     painter = QPainter(self)
     if not self.contentsRect().contains(event.rect()):
         painter.save()
         painter.setClipRegion(event.region() & self.frameRect())
         self.drawFrame(painter)
         painter.restore()
     painter.setClipRegion(event.region() & self.contentsRect())
     self.drawContents(painter)
Пример #7
0
 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)
Пример #8
0
    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)
Пример #9
0
    def drawSeries(self, seriesItem, from_, to):
        """When observing an measurement while it is running, new points have 
        to be added to an existing seriesItem. drawSeries() can be used to 
        display them avoiding a complete redraw of the canvas.

        Setting plot().canvas().setAttribute(Qt.WA_PaintOutsidePaintEvent, True)
        will result in faster painting, if the paint engine of the canvas widget
        supports this feature."""
        if seriesItem is None or seriesItem.plot() is None:
            return
        canvas = seriesItem.plot().canvas()
        canvasRect = canvas.contentsRect()
        plotCanvas = canvas  #XXX: cast to QwtPlotCanvas
        if plotCanvas and qwtHasBackingStore(plotCanvas):
            painter = QPainter(plotCanvas.backingStore())  #XXX: cast plotCanvas.backingStore() to QPixmap
            if self.__data.hasClipping:
                painter.setClipRegion(self.__data.clipRegion)
            qwtRenderItem(painter, canvasRect, seriesItem, from_, to)
            if self.testAttribute(self.FullRepaint):
                plotCanvas.repaint()
                return
        immediatePaint = True
        if not canvas.testAttribute(Qt.WA_WState_InPaintEvent):
            if QT_VERSION >= 0x050000 or\
               not canvas.testAttribute(Qt.WA_PaintOutsidePaintEvent):
                immediatePaint = False
        if immediatePaint:
            if not self.__data.painter.isActive():
                self.reset()
                self.__data.painter.begin(canvas)
                canvas.installEventFilter(self)
            if self.__data.hasClipping:
                self.__data.painter.setClipRegion(
                        QRegion(canvasRect) & self.__data.clipRegion)
            elif not self.__data.painter.hasClipping():
                self.__data.painter.setClipRect(canvasRect)
            qwtRenderItem(self.__data.painter,
                          canvasRect, seriesItem, from_, to)
            if self.__data.attributes & self.AtomicPainter:
                self.reset()
            elif self.__data.hasClipping:
                self.__data.painter.setClipping(False)
        else:
            self.reset()
            self.__data.seriesItem = seriesItem
            self.__data.from_ = from_
            self.__data.to = to
            clipRegion = QRegion(canvasRect)
            if self.__data.hasClipping:
                clipRegion &= self.__data.clipRegion
            canvas.installEventFilter(self)
            canvas.repaint(clipRegion)
            canvas.removeEventFilter(self)
            self.__data.seriesItem = None
Пример #10
0
 def fillPixmap(self, widget, pixmap, offset=None):
     if offset is None:
         offset = QPoint()
     rect = QRect(offset, pixmap.size())
     painter = QPainter(pixmap)
     painter.translate(-offset)
     autoFillBrush = widget.palette().brush(widget.backgroundRole())
     if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
         bg = widget.palette().brush(QPalette.Window)
         qwtFillRect(widget, painter, rect, bg)
     if widget.autoFillBackground():
         qwtFillRect(widget, painter, rect, autoFillBrush)
     if widget.testAttribute(Qt.WA_StyledBackground):
         painter.setClipRegion(rect)
         opt = QStyleOption()
         opt.initFrom(widget)
         widget.style().drawPrimitive(QStyle.PE_Widget, opt,
                                      painter, widget)
Пример #11
0
 def fillPixmap(self, widget, pixmap, offset=None):
     if offset is None:
         offset = QPoint()
     rect = QRect(offset, pixmap.size())
     painter = QPainter(pixmap)
     painter.translate(-offset)
     autoFillBrush = widget.palette().brush(widget.backgroundRole())
     if not (widget.autoFillBackground() and autoFillBrush.isOpaque()):
         bg = widget.palette().brush(QPalette.Window)
         qwtFillRect(widget, painter, rect, bg)
     if widget.autoFillBackground():
         qwtFillRect(widget, painter, rect, autoFillBrush)
     if widget.testAttribute(Qt.WA_StyledBackground):
         painter.setClipRegion(rect)
         opt = QStyleOption()
         opt.initFrom(widget)
         widget.style().drawPrimitive(QStyle.PE_Widget, opt, painter,
                                      widget)
Пример #12
0
 def paintEvent(self, e):
     cr = self.contentsRect()
     painter = QPainter(self)
     painter.setClipRegion(e.region())
     if self.__data.isDown:
         qDrawWinButton(painter, 0, 0, self.width(), self.height(),
                        self.palette(), True)
     painter.save()
     if self.__data.isDown:
         shiftSize = buttonShift(self)
         painter.translate(shiftSize.width(), shiftSize.height())
     painter.setClipRect(cr)
     self.drawContents(painter)
     if not self.__data.icon.isNull():
         iconRect = QRect(cr)
         iconRect.setX(iconRect.x() + self.margin())
         if self.__data.itemMode != QwtLegendData.ReadOnly:
             iconRect.setX(iconRect.x() + BUTTONFRAME)
         iconRect.setSize(self.__data.icon.size())
         iconRect.moveCenter(QPoint(iconRect.center().x(), cr.center().y()))
         painter.drawPixmap(iconRect, self.__data.icon)
     painter.restore()
Пример #13
0
 def eventFilter(self, obj_, event):
     if event.type() == QEvent.Paint:
         self.reset()
         if self.__data.seriesItem:
             pe = event  #XXX: cast to QPaintEvent
             canvas = self.__data.seriesItem.plot().canvas()
             painter = QPainter(canvas)
             painter.setClipRegion(pe.region())
             doCopyCache = self.testAttribute(self.CopyBackingStore)
             if doCopyCache:
                 plotCanvas = canvas  #XXX: cast to QwtPlotCanvas
                 if plotCanvas:
                     doCopyCache = qwtHasBackingStore(plotCanvas)
                     if doCopyCache:
                         painter.drawPixmap(plotCanvas.contentsRect().topLeft(),
                                            plotCanvas.backingStore())
             if not doCopyCache:
                 qwtRenderItem(painter, canvas.contentsRect(),
                               self.__data.seriesItem,
                               self.__data.from_, self.__data.to)
             return True
     return False
Пример #14
0
 def eventFilter(self, obj_, event):
     if event.type() == QEvent.Paint:
         self.reset()
         if self.__data.seriesItem:
             pe = event  #XXX: cast to QPaintEvent
             canvas = self.__data.seriesItem.plot().canvas()
             painter = QPainter(canvas)
             painter.setClipRegion(pe.region())
             doCopyCache = self.testAttribute(self.CopyBackingStore)
             if doCopyCache:
                 plotCanvas = canvas  #XXX: cast to QwtPlotCanvas
                 if plotCanvas:
                     doCopyCache = qwtHasBackingStore(plotCanvas)
                     if doCopyCache:
                         painter.drawPixmap(plotCanvas.contentsRect().topLeft(),
                                            plotCanvas.backingStore())
             if not doCopyCache:
                 qwtRenderItem(painter, canvas.contentsRect(),
                               self.__data.seriesItem,
                               self.__data.from_, self.__data.to)
             return True
     return False
Пример #15
0
 def paintEvent(self, e):
     cr = self.contentsRect()
     painter = QPainter(self)
     painter.setClipRegion(e.region())
     if self.__data.isDown:
         qDrawWinButton(painter, 0, 0, self.width(), self.height(),
                        self.palette(), True)
     painter.save()
     if self.__data.isDown:
         shiftSize = buttonShift(self)
         painter.translate(shiftSize.width(), shiftSize.height())
     painter.setClipRect(cr)
     self.drawContents(painter)
     if not self.__data.icon.isNull():
         iconRect = QRect(cr)
         iconRect.setX(iconRect.x()+self.margin())
         if self.__data.itemMode != QwtLegendData.ReadOnly:
             iconRect.setX(iconRect.x()+BUTTONFRAME)
         iconRect.setSize(self.__data.icon.size())
         iconRect.moveCenter(QPoint(iconRect.center().x(),
                                    cr.center().y()))
         painter.drawPixmap(iconRect, self.__data.icon)
     painter.restore()