Python PySide2.QtGui.QPainter() Examples

The following are 29 code examples of PySide2.QtGui.QPainter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PySide2.QtGui , or try the search function .
Example #1
Source File: draw.py    From pyrdp with GNU General Public License v3.0 7 votes vote down vote up
def _brush(self, b: Brush, p: QPainter):
        """Configure the given brush."""
        brush = None

        if b.index is not None:  # This is a cached brush.
            brush = self.brushes.get(b.index)
        elif b.style == BrushStyle.PATTERN:
            pm = QPixmap.loadFromData(b.data, _fmt[b.bpp])
            brush = QBrush(pm)
        elif b.style == BrushStyle.HATCHED:
            brush = QBrush(_hs[b.hatch])
        else:
            brush = QBrush(_bs[b.style])

        p.setBrush(brush)
        p.setBrushOrigin(b.x, b.y)

    # Drawing API. 
Example #2
Source File: core.py    From pylash_engine with MIT License 6 votes vote down vote up
def _onShow(self):
		self.canvas.begin(self.canvasWidget)

		if self.useAntialiasing:
			self.canvas.setRenderHint(QtGui.QPainter.Antialiasing, True)
		else:
			self.canvas.setRenderHint(QtGui.QPainter.Antialiasing, False)

		if self.backgroundColor is not None:
			self.canvas.fillRect(0, 0, self.width, self.height, getColor(self.backgroundColor))
		else:
			self.canvas.eraseRect(0, 0, self.width, self.height)

		self._showDisplayList(self.childList)

		self.canvas.end() 
Example #3
Source File: display.py    From pylash_engine with MIT License 6 votes vote down vote up
def draw(self, source):
		if not isinstance(source, DisplayObject):
			raise TypeError("BitmapData.draw(source): parameter 'source' must be a display object.")

		w = source.endX()
		h = source.endY()

		self.image = QtGui.QPixmap(w, h)
		self.image.fill(QtCore.Qt.transparent)
		
		p = QtGui.QPainter()
		p.begin(self.image)

		if stage.useAntialiasing:
			p.setRenderHint(QtGui.QPainter.Antialiasing, True)
		else:
			p.setRenderHint(QtGui.QPainter.Antialiasing, False)

		source._show(p)

		p.end()

		self.width = w
		self.height = h 
Example #4
Source File: display.py    From pylash_engine with MIT License 6 votes vote down vote up
def __getCompositionMode(self):
		v = self.blendMode

		if v == BlendMode.SOURCE_ATOP:
			return QtGui.QPainter.CompositionMode_SourceAtop
		elif v == BlendMode.SOURCE_IN:
			return QtGui.QPainter.CompositionMode_SourceIn
		elif v == BlendMode.SOURCE_OUT:
			return QtGui.QPainter.CompositionMode_SourceOut
		elif v == BlendMode.DESTINATION_OVER:
			return QtGui.QPainter.CompositionMode_DestinationOver
		elif v == BlendMode.DESTINATION_ATOP:
			return QtGui.QPainter.CompositionMode_DestinationAtop
		elif v == BlendMode.DESTINATION_IN:
			return QtGui.QPainter.CompositionMode_DestinationIn
		elif v == BlendMode.DESTINATION_OUT:
			return QtGui.QPainter.CompositionMode_DestinationOut
		elif v == BlendMode.LIGHTER:
			return QtGui.QPainter.CompositionMode_Lighter
		elif v == BlendMode.COPY:
			return QtGui.QPainter.CompositionMode_Copy
		elif v == BlendMode.XOR:
			return QtGui.QPainter.CompositionMode_Xor
		else:
			return QtGui.QPainter.CompositionMode_SourceOver 
Example #5
Source File: qt.py    From pyrdp with GNU General Public License v3.0 6 votes vote down vote up
def notifyImage(self, x: int, y: int, qimage: QImage, width: int, height: int):
        """
        Draw an image on the buffer.
        :param x: x position of the new image
        :param y: y position of the new image
        :param qimage: new QImage
        :param width: width of the new image
        :param height: height of the new image
        """

        # Fill buffer image
        qp = QPainter(self._buffer)
        qp.drawImage(x, y, qimage, 0, 0, width, height)

        # Force update
        self.update() 
Example #6
Source File: draw.py    From pyrdp with GNU General Public License v3.0 6 votes vote down vote up
def draw(self, glyph: GlyphEntry, p: QPainter):
        """Render a glyph using the given painter."""
        # Adjust the glyph coordinates to center it on origin
        x = self.x + glyph.x
        y = self.y + glyph.y

        if not self.fOpRedundant:
            p.fillRect(x, y, glyph.w, glyph.h, rgb_to_qcolor(self.fg))

        p.setBrush(QBrush(rgb_to_qcolor(self.bg), glyph.bitmap))
        p.setBrushOrigin(x, y)
        p.drawRect(x, y, glyph.w, glyph.h)

        if self.flAccel & SO_CHAR_INC_EQUAL_BM_BASE:
            self.x += glyph.w


# Map brush styles to Qt brush style 
Example #7
Source File: colorwheel.py    From hotbox_designer with BSD 3-Clause Clear License 5 votes vote down vote up
def paintEvent(self, _):
        painter = QtGui.QPainter()
        painter.begin(self)
        self.paint(painter)
        painter.end() 
Example #8
Source File: canvas.py    From spore with MIT License 5 votes vote down vote up
def paintEvent(self, event):

        super(CircularBrush, self).paintEvent(event)

        # draw brush
        if hasattr(self, 'brush_state') and self.brush_state.draw:
            painter = QPainter()
            shapes = self.create_brush_shape()
            for shape in shapes:
                shape = [QPointF(point[0], point[1]) for point in shape]

                path = QPainterPath()
                start_pos = shape.pop(0)
                path.moveTo(start_pos)
                [path.lineTo(point) for point in shape]

                painter.setRenderHint(painter.Antialiasing)
                #  painter.setRenderHint(painter.HighQualityAnti)
                painter.begin(self)

                painter.setPen(QPen(Qt.red, 1))
                painter.drawPath(path)

            painter.end() 
Example #9
Source File: core.py    From pylash_engine with MIT License 5 votes vote down vote up
def _setCanvas(self, speed, title, width, height):
		self.speed = speed
		self.width = width
		self.height = height

		self.canvas = QtGui.QPainter()

		self.canvasWidget = CanvasWidget()
		self.canvasWidget.setWindowTitle(title)
		self.canvasWidget.setFixedSize(width, height)
		self.canvasWidget.show()

		self.timer = QtCore.QTimer()
		self.timer.setInterval(speed)
		self.timer.start()

		self.timer.timeout.connect(self.canvasWidget.update) 
Example #10
Source File: draw_override.py    From spore with MIT License 5 votes vote down vote up
def paintEvent(self, event):
        painter = QPainter()
        painter.setRenderHint(painter.Antialiasing)
        #  painter.setRenderHint(painter.HighQualityAnti)

        painter.begin(self)

        print 'paint something', event
        #  path = QPainterPath()
        painter.setPen(QPen(Qt.yellow, 5))
        painter.drawEllipse(50, 50, 50, 50)



        painter.end() 
Example #11
Source File: pyqt.py    From mgear_core with MIT License 5 votes vote down vote up
def get_icon(icon, size=24):
    """get svg icon from icon resources folder as a pixel map
    """
    img = get_icon_path("{}.svg".format(icon))
    svg_renderer = QtSvg.QSvgRenderer(img)
    image = QtGui.QImage(size, size, QtGui.QImage.Format_ARGB32)
    # Set the ARGB to 0 to prevent rendering artifacts
    image.fill(0x00000000)
    svg_renderer.render(QtGui.QPainter(image))
    pixmap = QtGui.QPixmap.fromImage(image)

    return pixmap 
Example #12
Source File: base_plugin.py    From angr-management with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def draw_insn(self, qinsn: QInstruction, painter: QPainter):
        pass 
Example #13
Source File: qtrace_viewer.py    From angr-management with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def _show_legend(self):
        pen = QPen(Qt.transparent)

        gradient = self._make_legend_gradient(self.LEGEND_X, self.LEGEND_Y,
                                   self.LEGEND_X, self.LEGEND_Y + self.legend_height)
        brush = QBrush(gradient)
        self.legend = self.scene.addRect(self.LEGEND_X, self.LEGEND_Y,
                                         self.LEGEND_WIDTH, self.legend_height, pen, brush)

        reference_gradient = self._make_legend_gradient(0, 0, self.LEGEND_WIDTH, 1000)
        base_img = QImage(self.LEGEND_WIDTH, 1000, QImage.Format.Format_ARGB32)
        p = QPainter(base_img)
        p.fillRect(base_img.rect(),reference_gradient)
        self.legend_img = base_img #reference shade 
Example #14
Source File: qmemory_viewer.py    From angr-management with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def paintEvent(self, event):

        if self.address is None:
            return

        MARGIN_LEFT = 5
        MARGIN_TOP = 5
        LINE_MARGIN = 3

        painter = QPainter(self)

        painter.setPen(QPen(Qt.black, 1))
        painter.setFont(Conf.symexec_font)

        x = MARGIN_LEFT
        y = MARGIN_TOP

        for obj in self._objects:

            obj_type = type(obj)

            if obj_type is NewLinePiece:
                # carriage return
                x = MARGIN_LEFT
                y += Conf.symexec_font_height + LINE_MARGIN
            elif obj_type is AddressPiece:
                # address
                addr_str = "%08x" % obj.address
                painter.drawText(x, y + Conf.symexec_font_ascent, addr_str)
                x += Conf.symexec_font_width * len(addr_str)
                x += 7
            elif obj_type is QASTViewer:
                # AST viewer
                obj.x = x
                obj.y = y
                obj.paint(painter)

                x += obj.width + 2
            else:
                raise TypeError('paintEvent(): Unsupported object type %s.' % obj_type) 
Example #15
Source File: qast_viewer.py    From angr-management with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def paint(self, painter):
        """

        :param QPainter painter:
        :return:
        """

        if self.x is None or self.y is None:
            # paint() is called before x and y are set
            return

        painter.drawText(self.x, self.y + Conf.symexec_font_ascent, self._ast_str) 
Example #16
Source File: qgraph_object.py    From angr-management with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def paint(self, painter):
        """

        :param QPainter painter: The painter object.
        :return:                 None
        """

        raise NotImplementedError() 
Example #17
Source File: LNTextEdit.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def numberbarPaint(self, number_bar, event):
            font_metrics = self.fontMetrics()
            current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
 
            block = self.firstVisibleBlock()
            line_count = block.blockNumber()
            painter = QtGui.QPainter(number_bar)
            painter.fillRect(event.rect(), self.palette().base())
 
            # Iterate over all visible text blocks in the document.
            while block.isValid():
                line_count += 1
                block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
 
                # Check if the position of the block is out side of the visible
                # area.
                if not block.isVisible() or block_top >= event.rect().bottom():
                    break
 
                # We want the line number for the selected line to be bold.
                if line_count == current_line:
                    font = painter.font()
                    font.setBold(True)
                    painter.setFont(font)
                else:
                    font = painter.font()
                    font.setBold(False)
                    painter.setFont(font)
 
                # Draw the line number right justified at the position of the line.
                paint_rect = QtCore.QRect(0, block_top, number_bar.width(), font_metrics.height())
                painter.drawText(paint_rect, QtCore.Qt.AlignRight, unicode(line_count))
 
                block = block.next()
 
            painter.end() 
Example #18
Source File: qt.py    From pyrdp with GNU General Public License v3.0 5 votes vote down vote up
def paintEvent(self, e: QEvent):
        """
        Call when Qt renderer engine estimate that is needed
        :param e: the event
        """
        ratio = self.ratio if self.scaleToWindow else 1
        qp = QPainter(self)
        qp.drawImage(0, 0, self._buffer.scaled(self.sessionWidth * ratio, self.sessionHeight * ratio, aspectMode=Qt.KeepAspectRatio))
        qp.setBrush(QColor.fromRgb(255, 255, 0, 180))
        qp.drawEllipse(QPoint(self.mouseX * ratio, self.mouseY * ratio), 5, 5) 
Example #19
Source File: reader.py    From hotbox_designer with BSD 3-Clause Clear License 5 votes vote down vote up
def paintEvent(self, _):
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        # this is a workaround because a fully transparent widget doesn't
        # execute the mouseMove event when the cursor is hover a
        # transparent of the widget. This draw the reader rect has black
        # rect with a 1/255 transparency value
        draw_aiming_background(painter, self.rect())

        for shape in self.shapes:
            shape.draw(painter)
        if self.aiming:
            draw_aiming(painter, self.center, get_cursor(self))
        painter.end() 
Example #20
Source File: Mp4EventHandler.py    From pyrdp with GNU General Public License v3.0 5 votes vote down vote up
def notifyImage(self, x: int, y: int, img: QImage, w: int, h: int):
        p = QPainter(self._buffer)
        p.drawImage(x, y, img, 0, 0, w, h) 
Example #21
Source File: colorwheel.py    From hotbox_designer with BSD 3-Clause Clear License 5 votes vote down vote up
def paint(self, painter):
        painter.setRenderHint(QtGui.QPainter.Antialiasing)

        pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 0))
        pen.setWidth(0)
        pen.setJoinStyle(QtCore.Qt.MiterJoin)

        painter.setBrush(self._conicalGradient)
        painter.setPen(pen)
        painter.drawRoundedRect(
            6, 6, (self.width() - 12), (self.height() - 12),
            self.width(), self.height())

        painter.setBrush(self.palette().color(QtGui.QPalette.Background))
        painter.drawRoundedRect(
            12.5, 12.5, (self.width() - 25), (self.height() - 25),
            self.width(), self.height())

        self._horizontal_gradient.setColorAt(
            1.0, self._get_current_wheel_color())
        painter.setBrush(self._horizontal_gradient)
        painter.drawRect(self._rect)

        painter.setBrush(self._vertical_gradient)
        painter.drawRect(self._rect)

        pen.setColor(QtGui.QColor(BLACK))
        pen.setWidth(3)
        painter.setPen(pen)

        angle = math.radians(self._angle)
        painter.drawLine(
            get_point_on_line(angle, 37),
            get_point_on_line(angle, 46))

        pen.setWidth(5)
        pen.setCapStyle(QtCore.Qt.RoundCap)
        painter.setPen(pen)
        painter.drawPoint(self._color_point) 
Example #22
Source File: reader.py    From hotbox_designer with BSD 3-Clause Clear License 5 votes vote down vote up
def paintEvent(self, _):
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        for shape in self.shapes:
            shape.draw(painter)
        painter.end() 
Example #23
Source File: draw.py    From pyrdp with GNU General Public License v3.0 5 votes vote down vote up
def _end(self, p: QPainter):
        p.end() 
Example #24
Source File: draw.py    From pyrdp with GNU General Public License v3.0 5 votes vote down vote up
def _paint(self, dst: QImage):
        """Retrieve QPainter for the given surface."""
        p = QPainter(dst)
        p.setPen(Qt.NoPen)
        # Set the bounding rectangle if present.
        if self.bounds:
            x = self.bounds.left
            y = self.bounds.top
            w = self.bounds.right - x
            h = self.bounds.bottom - y

            p.setClipRect(x, y, w + 1, h + 1)
            p.setClipping(True)
        return p 
Example #25
Source File: GuiSlots.py    From PyAero with MIT License 5 votes vote down vote up
def handlePaintRequest(self, printer):
        printer.setOrientation(QtGui.QPrinter.Landscape)
        self.parent.view.render(QtGui.QPainter(printer)) 
Example #26
Source File: GraphicsView.py    From PyAero with MIT License 5 votes vote down vote up
def paintEvent(self, QPaintEvent):

        painter = QtGui.QPainter(self)

        self.pen.setColor(QtGui.QColor(80, 80, 100))
        self.pen.setWidthF(1.5)
        self.pen.setStyle(QtCore.Qt.DotLine)

        # zoom rect must be at least RUBBERBANDSIZE % of view to allow zoom
        if (QPaintEvent.rect().width() < RUBBERBANDSIZE * self.view.width()) \
            or \
           (QPaintEvent.rect().height() < RUBBERBANDSIZE * self.view.height()):

            self.brush.setStyle(QtCore.Qt.NoBrush)

            # set boolean for allowing zoom
            self.allow_zoom = False
        else:
            # if rubberband rect is big enough indicate this by fill color
            color = QtGui.QColor(10, 30, 140, 45)
            self.brush.setColor(color)
            self.brush.setStyle(QtCore.Qt.SolidPattern)

            # set boolean for allowing zoom
            self.allow_zoom = True

        painter.setBrush(self.brush)
        painter.setPen(self.pen)
        painter.drawRect(QPaintEvent.rect()) 
Example #27
Source File: Rush.py    From rush with MIT License 5 votes vote down vote up
def paintEvent(self, event):
        super(CustomQLineEdit, self).paintEvent(event)

        painter = QtGui.QPainter(self)
        painter.setOpacity(0.75)
        height = self.iconPixmap.height()
        rightBorder = 8
        painter.drawPixmap(
            rightBorder+2, (self.height() - height) / 2, self.iconPixmap) 
Example #28
Source File: editarea.py    From hotbox_designer with BSD 3-Clause Clear License 5 votes vote down vote up
def paintEvent(self, _):
        painter = QtGui.QPainter()
        painter.begin(self)
        self.paint(painter)
        painter.end() 
Example #29
Source File: GraphicsView.py    From PyAero with MIT License 4 votes vote down vote up
def __init__(self, parent=None, scene=None):
        """Default settings for graphicsview instance

        Args:
            parent (QMainWindow, optional): mainwindow instance
        """

        super().__init__(scene)

        self.parent = parent

        self._leftMousePressed = False

        # allow drops from drag and drop
        self.setAcceptDrops(True)

        # use custom rubberband
        self.rubberband = RubberBand(QtWidgets.QRubberBand.Rectangle, self)

        # needed for correct mouse wheel zoom
        # otherwise mouse anchor is wrong; it would use (0, 0)
        self.setInteractive(True)

        # set QGraphicsView attributes
        self.setRenderHints(QtGui.QPainter.Antialiasing |
                            QtGui.QPainter.TextAntialiasing)
        self.setViewportUpdateMode(QtWidgets.QGraphicsView.FullViewportUpdate)
        self.setResizeAnchor(QtWidgets.QGraphicsView.AnchorViewCenter)

        # view behaviour when zooming
        if ZOOMANCHOR == 'mouse':
            # point under mouse pointer stays fixed during zoom
            self.setTransformationAnchor(
                QtWidgets.QGraphicsView.AnchorUnderMouse)
        else:
            # view center stays fixed during zoom
            self.setTransformationAnchor(
                QtWidgets.QGraphicsView.AnchorViewCenter)

        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

        # normally (0, 0) is upperleft corner of view
        # swap y-axis in order to make (0, 0) lower left
        # and y-axis pointing upwards
        self.scale(1, -1)

        # cache view to be able to keep it during resize
        self.getSceneFromView()

        # set background style and color for view
        self.setBackground(VIEWSTYLE)