示例#1
0
 def drawColorBar(self, painter, colorMap, interval, scaleMap, orientation,
                  rect):
     colorTable = []
     if colorMap.format() == QwtColorMap.Indexed:
         colorTable = colorMap.colorTable(interval)
     c = QColor()
     devRect = rect.toAlignedRect()
     pixmap = QPixmap(devRect.size())
     pixmap.fill(Qt.transparent)
     pmPainter = QPainter(pixmap)
     pmPainter.translate(-devRect.x(), -devRect.y())
     if orientation == Qt.Horizontal:
         sMap = scaleMap
         sMap.setPaintInterval(rect.left(), rect.right())
         for x in range(devRect.left(), devRect.right() + 1):
             value = sMap.invTransform(x)
             if colorMap.format() == QwtColorMap.RGB:
                 c.setRgba(colorMap.rgb(interval, value))
             else:
                 c = colorTable[colorMap.colorIndex(interval, value)]
             pmPainter.setPen(c)
             pmPainter.drawLine(x, devRect.top(), devRect.bottom())
     else:
         sMap = scaleMap
         sMap.setPaintInterval(rect.bottom(), rect.top())
         for y in range(devRect.top(), devRect.bottom() + 1):
             value = sMap.invTransform(y)
             if colorMap.format() == QwtColorMap.RGB:
                 c.setRgba(colorMap.rgb(interval, value))
             else:
                 c = colorTable[colorMap.colorIndex(interval, value)]
             pmPainter.setPen(c)
             pmPainter.drawLine(devRect.left(), y, devRect.right(), y)
     pmPainter.end()
     self.drawPixmap(painter, rect, pixmap)
示例#2
0
 def drawColorBar(self, painter, colorMap, interval, scaleMap,
                  orientation, rect):
     colorTable = []
     if colorMap.format() == QwtColorMap.Indexed:
         colorTable = colorMap.colorTable(interval)
     c = QColor()
     devRect = rect.toAlignedRect()
     pixmap = QPixmap(devRect.size())
     pixmap.fill(Qt.transparent)
     pmPainter = QPainter(pixmap)
     pmPainter.translate(-devRect.x(), -devRect.y())
     if orientation == Qt.Horizontal:
         sMap = scaleMap
         sMap.setPaintInterval(rect.left(), rect.right())
         for x in range(devRect.left(), devRect.right()+1):
             value = sMap.invTransform(x)
             if colorMap.format() == QwtColorMap.RGB:
                 c.setRgba(colorMap.rgb(interval, value))
             else:
                 c = colorTable[colorMap.colorIndex(interval, value)]
             pmPainter.setPen(c)
             pmPainter.drawLine(x, devRect.top(), devRect.bottom())
     else:
         sMap = scaleMap
         sMap.setPaintInterval(rect.bottom(), rect.top())
         for y in range(devRect.top(), devRect.bottom()+1):
             value = sMap.invTransform(y)
             if colorMap.format() == QwtColorMap.RGB:
                 c.setRgba(colorMap.rgb(interval, value))
             else:
                 c = colorTable[colorMap.colorIndex(interval, value)]
             pmPainter.setPen(c)
             pmPainter.drawLine(devRect.left(), y, devRect.right(), y)
     pmPainter.end()
     self.drawPixmap(painter, rect, pixmap)
示例#3
0
 def setPaintAttribute(self, attribute, on=True):
     if bool(self.__data.paintAttributes & attribute) == on:
         return
     if on:
         self.__data.paintAttributes |= attribute
     else:
         self.__data.paintAttributes &= ~attribute
     if attribute == self.BackingStore:
         if on:
             if self.__data.backingStore is None:
                 self.__data.backingStore = QPixmap()
             if self.isVisible():
                 if QT_VERSION >= 0x050000:
                     self.__data.backingStore = self.grab(self.rect())
                 else:
                     if PYQT5:
                         pm = QPixmap.grabWidget(self, self.rect())
                     else:
                         pm = self.grab(self.rect())
                     self.__data.backingStore = pm
         else:
             self.__data.backingStore = None
     elif attribute == self.Opaque:
         if on:
             self.setAttribute(Qt.WA_OpaquePaintEvent, True)
     elif attribute in (self.HackStyledBackground, self.ImmediatePaint):
         pass
示例#4
0
 def backingStore(self, widget, size):
     """
     :param QWidget widget: Widget, for which the backinstore is intended
     :param QSize size: Size of the pixmap
     :return: A pixmap that can be used as backing store
     """
     if QT_VERSION >= 0x050000:
         pixelRatio = 1.
         if widget and widget.windowHandle():
             pixelRatio = widget.windowHandle().devicePixelRatio()
         else:
             from qwt.qt.QtGui import qApp
             if qApp is not None:
                 try:
                     pixelRatio = qApp.devicePixelRatio()
                 except RuntimeError:
                     pass
         pm = QPixmap(size * pixelRatio)
         pm.setDevicePixelRatio(pixelRatio)
     else:
         pm = QPixmap(size)
     if QT_VERSION < 0x050000 and widget and isX11GraphicsSystem():
         if pm.x11Info().screen() != widget.x11Info().screen():
             pm.x11SetScreen(widget.x11Info().screen())
     return pm
示例#5
0
 def toPixmap(self, *args):
     if len(args) == 0:
         if self.isNull():
             return QPixmap()
         sz = self.defaultSize()
         w = np.ceil(sz.width())
         h = np.ceil(sz.height())
         pixmap = QPixmap(w, h)
         pixmap.fill(Qt.transparent)
         r = QRectF(0., 0., sz.width(), sz.height())
         painter = QPainter(pixmap)
         self.render(painter, r, Qt.KeepAspectRatio)
         painter.end()
         return pixmap
     elif len(args) in (1, 2):
         size = args[0]
         aspectRatioMode = Qt.IgnoreAspectRatio
         if len(args) == 2:
             aspectRatioMode = args[-1]
         pixmap = QPixmap(size)
         pixmap.fill(Qt.transparent)
         r = QRect(0, 0, size.width(), size.height())
         painter = QPainter(pixmap)
         self.render(painter, r, aspectRatioMode)
         painter.end()
         return pixmap
示例#6
0
    def __init__(self, *args):
        QMainWindow.__init__(self, *args)

        self.plot = BodePlot(self)
        self.plot.setContentsMargins(5, 5, 5, 0)

        self.setContextMenuPolicy(Qt.NoContextMenu)

        self.setCentralWidget(self.plot)

        toolBar = QToolBar(self)
        self.addToolBar(toolBar)

        btnPrint = QToolButton(toolBar)
        btnPrint.setText("Print")
        btnPrint.setIcon(QIcon(QPixmap(print_xpm)))
        btnPrint.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnPrint)
        btnPrint.clicked.connect(self.print_)

        btnExport = QToolButton(toolBar)
        btnExport.setText("Export")
        btnExport.setIcon(QIcon(QPixmap(print_xpm)))
        btnExport.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnExport)
        btnExport.clicked.connect(self.exportDocument)

        btnSet = QToolButton(toolBar)
        btnSet.setText("Set")
        btnSet.setIcon(QIcon(QPixmap(print_xpm)))
        btnSet.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        toolBar.addWidget(btnSet)
        btnSet.clicked.connect(self.exportDocument)

        toolBar.addSeparator()

        dampBox = QWidget(toolBar)
        dampLayout = QHBoxLayout(dampBox)
        dampLayout.setSpacing(0)
        dampLayout.addWidget(QWidget(dampBox), 10)  # spacer
        dampLayout.addWidget(QLabel("Damping Factor", dampBox), 0)
        dampLayout.addSpacing(10)

        toolBar.addWidget(dampBox)

        self.statusBar()

        self.showInfo()
示例#7
0
 def setPaintAttribute(self, attribute, on=True):
     if bool(self.__data.paintAttributes & attribute) == on:
         return
     if on:
         self.__data.paintAttributes |= attribute
     else:
         self.__data.paintAttributes &= ~attribute
     if attribute == self.BackingStore:
         if on:
             if self.__data.backingStore is None:
                 self.__data.backingStore = QPixmap()
             if self.isVisible():
                 if QT_VERSION >= 0x050000:
                     self.__data.backingStore = self.grab(self.rect())
                 else:
                     if PYQT5:
                         pm = QPixmap.grabWidget(self, self.rect())
                     else:
                         pm = self.grab(self.rect())
                     self.__data.backingStore = pm
         else:
             self.__data.backingStore = None
     elif attribute == self.Opaque:
         if on:
             self.setAttribute(Qt.WA_OpaquePaintEvent, True)
     elif attribute in (self.HackStyledBackground, self.ImmediatePaint):
         pass
示例#8
0
文件: painter.py 项目: gyenney/Tools
 def backingStore(self, widget, size):
     """
     :param QWidget widget: Widget, for which the backinstore is intended
     :param QSize size: Size of the pixmap
     :return: A pixmap that can be used as backing store
     """
     if QT_VERSION >= 0x050000:
         pixelRatio = 1.
         if widget and widget.windowHandle():
             pixelRatio = widget.windowHandle().devicePixelRatio()
         else:
             from qwt.qt.QtGui import qApp
             if qApp is not None:
                 try:
                     pixelRatio = qApp.devicePixelRatio()
                 except RuntimeError:
                     pass
         pm = QPixmap(size*pixelRatio)
         pm.setDevicePixelRatio(pixelRatio)
     else:
         pm = QPixmap(size)
     if QT_VERSION < 0x050000 and widget and isX11GraphicsSystem():
         if pm.x11Info().screen() != widget.x11Info().screen():
             pm.x11SetScreen(widget.x11Info().screen())
     return pm
示例#9
0
文件: painter.py 项目: gyenney/Tools
 def drawColorBar(self, painter, colorMap, interval, scaleMap,
                  orientation, rect):
     """
     Draw a color bar into a rectangle
     
     :param QPainter painter: Painter
     :param qwt.color_map.QwtColorMap colorMap: Color map
     :param qwt.interval.QwtInterval interval: Value range
     :param qwt.scalemap.QwtScaleMap scaleMap: Scale map
     :param Qt.Orientation orientation: Orientation
     :param QRectF rect: Target rectangle
     """
     colorTable = []
     if colorMap.format() == QwtColorMap.Indexed:
         colorTable = colorMap.colorTable(interval)
     c = QColor()
     devRect = rect.toAlignedRect()
     pixmap = QPixmap(devRect.size())
     pixmap.fill(Qt.transparent)
     pmPainter = QPainter(pixmap)
     pmPainter.translate(-devRect.x(), -devRect.y())
     if orientation == Qt.Horizontal:
         sMap = QwtScaleMap(scaleMap)
         sMap.setPaintInterval(rect.left(), rect.right())
         for x in range(devRect.left(), devRect.right()+1):
             value = sMap.invTransform(x)
             if colorMap.format() == QwtColorMap.RGB:
                 c.setRgba(colorMap.rgb(interval, value))
             else:
                 c = colorTable[colorMap.colorIndex(interval, value)]
             pmPainter.setPen(c)
             pmPainter.drawLine(x, devRect.top(), x, devRect.bottom())
     else:
         sMap = QwtScaleMap(scaleMap)
         sMap.setPaintInterval(rect.bottom(), rect.top())
         for y in range(devRect.top(), devRect.bottom()+1):
             value = sMap.invTransform(y)
             if colorMap.format() == QwtColorMap.RGB:
                 c.setRgba(colorMap.rgb(interval, value))
             else:
                 c = colorTable[colorMap.colorIndex(interval, value)]
             pmPainter.setPen(c)
             pmPainter.drawLine(devRect.left(), y, devRect.right(), y)
     pmPainter.end()
     self.drawPixmap(painter, rect, pixmap)
示例#10
0
 def drawColorBar(self, painter, colorMap, interval, scaleMap, orientation,
                  rect):
     """
     Draw a color bar into a rectangle
     
     :param QPainter painter: Painter
     :param qwt.color_map.QwtColorMap colorMap: Color map
     :param qwt.interval.QwtInterval interval: Value range
     :param qwt.scalemap.QwtScaleMap scaleMap: Scale map
     :param Qt.Orientation orientation: Orientation
     :param QRectF rect: Target rectangle
     """
     colorTable = []
     if colorMap.format() == QwtColorMap.Indexed:
         colorTable = colorMap.colorTable(interval)
     c = QColor()
     devRect = rect.toAlignedRect()
     pixmap = QPixmap(devRect.size())
     pixmap.fill(Qt.transparent)
     pmPainter = QPainter(pixmap)
     pmPainter.translate(-devRect.x(), -devRect.y())
     if orientation == Qt.Horizontal:
         sMap = QwtScaleMap(scaleMap)
         sMap.setPaintInterval(rect.left(), rect.right())
         for x in range(devRect.left(), devRect.right() + 1):
             value = sMap.invTransform(x)
             if colorMap.format() == QwtColorMap.RGB:
                 c.setRgba(colorMap.rgb(interval, value))
             else:
                 c = colorTable[colorMap.colorIndex(interval, value)]
             pmPainter.setPen(c)
             pmPainter.drawLine(x, devRect.top(), x, devRect.bottom())
     else:
         sMap = QwtScaleMap(scaleMap)
         sMap.setPaintInterval(rect.bottom(), rect.top())
         for y in range(devRect.top(), devRect.bottom() + 1):
             value = sMap.invTransform(y)
             if colorMap.format() == QwtColorMap.RGB:
                 c.setRgba(colorMap.rgb(interval, value))
             else:
                 c = colorTable[colorMap.colorIndex(interval, value)]
             pmPainter.setPen(c)
             pmPainter.drawLine(devRect.left(), y, devRect.right(), y)
     pmPainter.end()
     self.drawPixmap(painter, rect, pixmap)
示例#11
0
文件: symbol.py 项目: gyenney/Tools
def qwtDrawPixmapSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    if size.isEmpty():
        size = symbol.pixmap().size()
    transform = QTransform(painter.transform())
    if transform.isScaling():
        r = QRect(0, 0, size.width(), size.height())
        size = transform.mapRect(r).size()
    pm = QPixmap(symbol.pixmap())
    if pm.size() != size:
        pm = pm.scaled(size)
    pinPoint = QPointF(.5 * size.width(), .5 * size.height())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    painter.resetTransform()
    for pos in points:
        pos = QPointF(transform.map(pos)) - pinPoint
        QwtPainter.drawPixmap(painter, QRect(pos.toPoint(), pm.size(), pm))
示例#12
0
文件: symbol.py 项目: gyenney/Tools
def qwtDrawPixmapSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    if size.isEmpty():
        size = symbol.pixmap().size()
    transform = QTransform(painter.transform())
    if transform.isScaling():
        r = QRect(0, 0, size.width(), size.height())
        size = transform.mapRect(r).size()
    pm = QPixmap(symbol.pixmap())
    if pm.size() != size:
        pm = pm.scaled(size)
    pinPoint = QPointF(.5*size.width(), .5*size.height())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    painter.resetTransform()
    for pos in points:
        pos = QPointF(transform.map(pos))-pinPoint
        QwtPainter.drawPixmap(painter, QRect(pos.toPoint(), pm.size(), pm))
示例#13
0
    def setPaintAttribute(self, attribute, on=True):
        """
        Changing the paint attributes

        Paint attributes:
        
            * `QwtPlotCanvas.BackingStore`
            * `QwtPlotCanvas.Opaque`
            * `QwtPlotCanvas.HackStyledBackground`
            * `QwtPlotCanvas.ImmediatePaint`
        
        :param int attribute: Paint attribute
        :param bool on: On/Off
        
        .. seealso::
        
            :py:meth:`testPaintAttribute()`, :py:meth:`backingStore()`
        """
        if bool(self.__data.paintAttributes & attribute) == on:
            return
        if on:
            self.__data.paintAttributes |= attribute
        else:
            self.__data.paintAttributes &= ~attribute
        if attribute == self.BackingStore:
            if on:
                if self.__data.backingStore is None:
                    self.__data.backingStore = QPixmap()
                if self.isVisible():
                    if QT_VERSION >= 0x050000:
                        self.__data.backingStore = self.grab(self.rect())
                    else:
                        if PYQT5:
                            pm = QPixmap.grabWidget(self, self.rect())
                        else:
                            pm = self.grab(self.rect())
                        self.__data.backingStore = pm
            else:
                self.__data.backingStore = None
        elif attribute == self.Opaque:
            if on:
                self.setAttribute(Qt.WA_OpaquePaintEvent, True)
        elif attribute in (self.HackStyledBackground, self.ImmediatePaint):
            pass
示例#14
0
 def mousePressEvent(self, event):
     if event.button() == Qt.LeftButton:
         if PYQT5:
             pm = self.grab()
         else:
             pm = QPixmap.grabWidget(self)
         color = QColor()
         color.setRgb(pm.toImage().pixel(event.x(), event.y()))
         self.colorSelected.emit(color)
         event.accept()
示例#15
0
 def mousePressEvent(self, event):
     if event.button() == Qt.LeftButton:
         if PYQT5:
             pm = self.grab()
         else:
             pm = QPixmap.grabWidget(self)
         color = QColor()
         color.setRgb(pm.toImage().pixel(event.x(), event.y()))
         self.SIG_COLOR_SELECTED.emit(color)
         event.accept()
示例#16
0
 def backingStore(self, widget, size):
     if QT_VERSION >= 0x050000:
         pixelRatio = 1.
         if widget and widget.windowHandle():
             pixelRatio = widget.windowHandle().devicePixelRatio()
         else:
             from qwt.qt.QtGui import qApp
             if qApp is not None:
                 try:
                     pixelRatio = qApp.devicePixelRatio()
                 except RuntimeError:
                     pass
         pm = QPixmap(size * pixelRatio)
         pm.setDevicePixelRatio(pixelRatio)
     else:
         pm = QPixmap(size)
     if QT_VERSION < 0x050000 and widget and isX11GraphicsSystem():
         if pm.x11Info().screen() != widget.x11Info().screen():
             pm.x11SetScreen(widget.x11Info().screen())
     return pm
示例#17
0
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)))
示例#18
0
文件: graphic.py 项目: gyenney/Tools
    def toPixmap(self, *args):
        """
        Convert the graphic to a `QPixmap`

        All pixels of the pixmap get initialized by `Qt.transparent`
        before the graphic is scaled and rendered on it.

        The size of the pixmap is the default size ( ceiled to integers )
        of the graphic.
        
        :return: The graphic as pixmap in default size

        .. seealso::
        
            :py:meth:`defaultSize()`, :py:meth:`toImage()`, :py:meth:`render()`
        """
        if len(args) == 0:
            if self.isNull():
                return QPixmap()
            sz = self.defaultSize()
            w = np.ceil(sz.width())
            h = np.ceil(sz.height())
            pixmap = QPixmap(w, h)
            pixmap.fill(Qt.transparent)
            r = QRectF(0., 0., sz.width(), sz.height())
            painter = QPainter(pixmap)
            self.render(painter, r, Qt.KeepAspectRatio)
            painter.end()
            return pixmap
        elif len(args) in (1, 2):
            size = args[0]
            aspectRatioMode = Qt.IgnoreAspectRatio
            if len(args) == 2:
                aspectRatioMode = args[-1]
            pixmap = QPixmap(size)
            pixmap.fill(Qt.transparent)
            r = QRect(0, 0, size.width(), size.height())
            painter = QPainter(pixmap)
            self.render(painter, r, aspectRatioMode)
            painter.end()
            return pixmap
示例#19
0
文件: symbol.py 项目: gyenney/Tools
    def invalidateCache(self):
        """
        Invalidate the cached symbol pixmap

        The symbol invalidates its cache, whenever an attribute is changed
        that has an effect ob how to display a symbol. In case of derived
        classes with individual styles (>= `QwtSymbol.UserStyle`) it
        might be necessary to call invalidateCache() for attributes
        that are relevant for this style.

        .. seealso::
        
            :py:meth:`setCachePolicy()`, :py:meth:`drawSymbols()`
        """
        if self.__data.cache.pixmap is not None:
            self.__data.cache.pixmap = QPixmap()
示例#20
0
    def setPaintAttribute(self, attribute, on=True):
        """
        Changing the paint attributes

        Paint attributes:
        
            * `QwtPlotCanvas.BackingStore`
            * `QwtPlotCanvas.Opaque`
            * `QwtPlotCanvas.HackStyledBackground`
            * `QwtPlotCanvas.ImmediatePaint`
        
        :param int attribute: Paint attribute
        :param bool on: On/Off
        
        .. seealso::
        
            :py:meth:`testPaintAttribute()`, :py:meth:`backingStore()`
        """
        if bool(self.__data.paintAttributes & attribute) == on:
            return
        if on:
            self.__data.paintAttributes |= attribute
        else:
            self.__data.paintAttributes &= ~attribute
        if attribute == self.BackingStore:
            if on:
                if self.__data.backingStore is None:
                    self.__data.backingStore = QPixmap()
                if self.isVisible():
                    if QT_VERSION >= 0x050000:
                        self.__data.backingStore = self.grab(self.rect())
                    else:
                        if PYQT5:
                            pm = QPixmap.grabWidget(self, self.rect())
                        else:
                            pm = self.grab(self.rect())
                        self.__data.backingStore = pm
            else:
                self.__data.backingStore = None
        elif attribute == self.Opaque:
            if on:
                self.setAttribute(Qt.WA_OpaquePaintEvent, True)
        elif attribute in (self.HackStyledBackground, self.ImmediatePaint):
            pass
示例#21
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().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()
示例#22
0
 def backingStore(self, widget, size):
     if QT_VERSION >= 0x050000:
         pixelRatio = 1.
         if widget and widget.windowHandle():
             pixelRatio = widget.windowHandle().devicePixelRatio()
         else:
             from qwt.qt.QtGui import qApp
             if qApp is not None:
                 try:
                     pixelRatio = qApp.devicePixelRatio()
                 except RuntimeError:
                     pass
         pm = QPixmap(size*pixelRatio)
         pm.setDevicePixelRatio(pixelRatio)
     else:
         pm = QPixmap(size)
     if QT_VERSION < 0x050000 and widget and isX11GraphicsSystem():
         if pm.x11Info().screen() != widget.x11Info().screen():
             pm.x11SetScreen(widget.x11Info().screen())
     return pm
示例#23
0
    def findAscent(self, font):
        dummy = "E"
        white = QColor(Qt.white)

        fm = self.fontmetrics(font)
        pm = QPixmap(fm.width(dummy), fm.height())
        pm.fill(white)

        p = QPainter(pm)
        p.setFont(font)
        p.drawText(0, 0, pm.width(), pm.height(), 0, dummy)
        p.end()

        img = pm.toImage()

        w = pm.width()
        linebytes = w * 4
        for row in range(img.height()):
            line = img.scanLine(row).asstring(linebytes)
            for col in range(w):
                color = struct.unpack('I', line[col * 4:(col + 1) * 4])[0]
                if color != white.rgb():
                    return fm.ascent() - row + 1
        return fm.ascent()
示例#24
0
 def _save_display(self, chartplot):
     self._png_number += 1
     # put together filename components
     name_components = []
     if self._grab_name:
         name_components.append(self._grab_name)
     if self._menu.isVellsControlVisible():
         name_components.append(str(self._menu.vells_component))
     if self._menu.isComplexControlVisible():
         name_components.append(
             str(self._menu.ComplexComponentLabels[
                 self._menu.complex_component]))
     if len(self._ChartPlot) > 1:
         name_components.append(chartplot.dataLabel())
     name_components.append(str(self._png_number))
     save_file = "_".join(name_components).replace(' ', '_') + ".png"
     try:
         pm = QPixmap.grabWidget(chartplot)
         pm.save(save_file, "PNG")
         return save_file, None
     except:
         traceback.print_exc()
         print('failed to grab or save pixmap')
         return save_file, True
示例#25
0
    def findAscent(self, font):
        dummy = "E"
        white = QColor(Qt.white)

        fm = self.fontmetrics(font)
        pm = QPixmap(fm.width(dummy), fm.height())
        pm.fill(white)
        
        p = QPainter(pm)
        p.setFont(font)
        p.drawText(0, 0, pm.width(), pm.height(), 0, dummy)
        p.end()
        
        img = pm.toImage()
        
        w = pm.width()
        linebytes = w*4
        for row in range(img.height()):
            line = img.scanLine(row).asstring(linebytes)
            for col in range(w):
                color = struct.unpack('I', line[col*4:(col+1)*4])[0]
                if color != white.rgb():
                    return fm.ascent()-row+1
        return fm.ascent()
示例#26
0
    def toPixmap(self, *args):
        """
        Convert the graphic to a `QPixmap`

        All pixels of the pixmap get initialized by `Qt.transparent`
        before the graphic is scaled and rendered on it.

        The size of the pixmap is the default size ( ceiled to integers )
        of the graphic.
        
        :return: The graphic as pixmap in default size

        .. seealso::
        
            :py:meth:`defaultSize()`, :py:meth:`toImage()`, :py:meth:`render()`
        """
        if len(args) == 0:
            if self.isNull():
                return QPixmap()
            sz = self.defaultSize()
            w = np.ceil(sz.width())
            h = np.ceil(sz.height())
            pixmap = QPixmap(w, h)
            pixmap.fill(Qt.transparent)
            r = QRectF(0., 0., sz.width(), sz.height())
            painter = QPainter(pixmap)
            self.render(painter, r, Qt.KeepAspectRatio)
            painter.end()
            return pixmap
        elif len(args) in (1, 2):
            size = args[0]
            aspectRatioMode = Qt.IgnoreAspectRatio
            if len(args) == 2:
                aspectRatioMode = args[-1]
            pixmap = QPixmap(size)
            pixmap.fill(Qt.transparent)
            r = QRect(0, 0, size.width(), size.height())
            painter = QPainter(pixmap)
            self.render(painter, r, aspectRatioMode)
            painter.end()
            return pixmap
示例#27
0
 def invalidateBackingStore(self):
     if self.__data.backingStore:
         self.__data.backingStore = QPixmap()
示例#28
0
 def __init__(self):
     self.itemMode = QwtLegendData.ReadOnly
     self.isDown = False
     self.spacing = MARGIN
     self.legendData = QwtLegendData()
     self.icon = QPixmap()
示例#29
0
def isX11GraphicsSystem():
    pm = QPixmap(1, 1)
    painter = QPainter(pm)
    isX11 = painter.paintEngine().type() == QPaintEngine.X11
    del painter
    return isX11
示例#30
0
文件: symbol.py 项目: gyenney/Tools
 def __init__(self):
     self.pixmap = QPixmap()
示例#31
0
 def invalidateCache(self):
     if self.__data.cache.pixmap is not None:
         self.__data.cache.pixmap = QPixmap()
示例#32
0
 def invalidateBackingStore(self):
     """Invalidate the internal backing store"""
     if self.__data.backingStore:
         self.__data.backingStore = QPixmap()