本文整理匯總了Python中PySide2.QtGui.QPainter方法的典型用法代碼示例。如果您正苦於以下問題:Python QtGui.QPainter方法的具體用法?Python QtGui.QPainter怎麽用?Python QtGui.QPainter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PySide2.QtGui
的用法示例。
在下文中一共展示了QtGui.QPainter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: paintEvent
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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()
示例2: _brush
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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.
示例3: draw
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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
示例4: notifyImage
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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()
示例5: __getCompositionMode
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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
示例6: draw
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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
示例7: _setCanvas
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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)
示例8: _onShow
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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()
示例9: paintEvent
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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()
示例10: get_icon
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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
示例11: paintEvent
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
def paintEvent(self, _):
painter = QtGui.QPainter()
painter.begin(self)
self.paint(painter)
painter.end()
示例12: paint
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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)
示例13: paintEvent
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
def paintEvent(self, _):
painter = QtGui.QPainter()
painter.begin(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
for shape in self.shapes:
shape.draw(painter)
painter.end()
示例14: paintEvent
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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)
示例15: paintEvent
# 需要導入模塊: from PySide2 import QtGui [as 別名]
# 或者: from PySide2.QtGui import QPainter [as 別名]
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())