예제 #1
0
    def set_background_pixmap(self, pixmap_path):
        """
        Sets the background of the scene
        :param pixmap_path: str, path to the pixmap
        """

        pixmap = QPixmap(pixmap_path)
        if not pixmap.isNull():
            self._image_path = pixmap_path
            self._pixmap = pixmap
        else:
            self._image_path = ''
            self._pixmap = QPixmap()
        self.use_bg_image = True
예제 #2
0
class BackgroundImageScene(BaseScene, object):
    """
    Scene with image background drawing support
    """

    def __init__(self, parent=None):
        super(BackgroundImageScene, self).__init__(parent=parent)

        self._image_path = ''
        self._use_bg_image = True
        self._pixmap = QPixmap()

    @decorators.accepts(QPixmap)
    def get_pixmap(self):
        return self._pixmap

    @decorators.returns(QPixmap)
    def set_pixmap(self, value):
        self._pixmap = value

    @decorators.returns(bool)
    def get_use_bg_image(self):
        return self._use_bg_image

    @decorators.accepts(bool)
    def set_use_bg_image(self, value):
        self._use_bg_image = value
        self.update()

    pixmap = property(get_pixmap, set_pixmap)
    use_bg_image = property(get_use_bg_image, set_use_bg_image)

    def set_background_pixmap(self, pixmap_path):
        """
        Sets the background of the scene
        :param pixmap_path: str, path to the pixmap
        """

        pixmap = QPixmap(pixmap_path)
        if not pixmap.isNull():
            self._image_path = pixmap_path
            self._pixmap = pixmap
        else:
            self._image_path = ''
            self._pixmap = QPixmap()
        self.use_bg_image = True

    def clear_background_image(self):
        """
        Clears the background image
        """

        self._pixmap = QPixmap()
        self._image_path = ''
        self.use_bg_image = False

    def drawBackground(self, painter, rect):
        """
        Override draw background method to write out image as background
        """

        painter.setRenderHint(QPainter.Antialiasing)
        painter.fillRect(rect, self._color)
        painter.setPen(QPen(Qt.black, 0.5, Qt.DashLine))
        painter.setBrush(QColor(67, 255, 163))
        if self._use_bg_image and not self._pixmap.isNull():
            painter.drawPixmap(QPointF(0, 0), self._pixmap)