本文整理汇总了Python中PyQt5.QtGui.QPainterPath方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QPainterPath方法的具体用法?Python QtGui.QPainterPath怎么用?Python QtGui.QPainterPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui
的用法示例。
在下文中一共展示了QtGui.QPainterPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawMarker
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def drawMarker(self, x, y, qp: QtGui.QPainter, color: QtGui.QColor, number=0):
if self.markerAtTip:
y -= self.markerSize
pen = QtGui.QPen(color)
qp.setPen(pen)
qpp = QtGui.QPainterPath()
qpp.moveTo(x, y + self.markerSize)
qpp.lineTo(x - self.markerSize, y - self.markerSize)
qpp.lineTo(x + self.markerSize, y - self.markerSize)
qpp.lineTo(x, y + self.markerSize)
if self.filledMarkers:
qp.fillPath(qpp, color)
else:
qp.drawPath(qpp)
if self.drawMarkerNumbers:
number_x = x - 3
number_y = y - self.markerSize - 3
qp.drawText(number_x, number_y, str(number))
示例2: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def __init__(self, width, height, color, border=None):
"""
Initialize the icon.
:type width: T <= int | float
:type height: T <= int | float
:type color: str
:type border: str
"""
pixmap = QtGui.QPixmap(width, height)
painter = QtGui.QPainter(pixmap)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
path = QtGui.QPainterPath()
path.addRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QPointF(width, height)))
painter.fillPath(path, QtGui.QBrush(QtGui.QColor(color)))
if border:
painter.setPen(QtGui.QPen(QtGui.QColor(border), 0, QtCore.Qt.SolidLine))
painter.drawPath(path)
painter.end()
super().__init__(pixmap)
示例3: shape
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def shape(self):
"""
Returns the shape of this item as a QPainterPath in local coordinates.
:rtype: QPainterPath
"""
path = QtGui.QPainterPath()
path.addPath(self.selection.geometry())
path.addPolygon(self.head.geometry())
if self.isSelected():
for polygon in self.handles:
path.addEllipse(polygon.geometry())
for polygon in self.anchors.values():
path.addEllipse(polygon.geometry())
return path
示例4: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def __init__(self, width=20, height=20, brush=None, **kwargs):
"""
Initialize the node.
:type width: int
:type height: int
:type brush: QBrush
"""
super().__init__(**kwargs)
brush = brush or AttributeNode.DefaultBrush
pen = AttributeNode.DefaultPen
self.fpolygon = Polygon(QtGui.QPainterPath())
self.background = Polygon(QtCore.QRectF(-14, -14, 28, 28))
self.selection = Polygon(QtCore.QRectF(-14, -14, 28, 28))
self.polygon = Polygon(QtCore.QRectF(-10, -10, 20, 20), brush, pen)
self.label = NodeLabel(template='attribute', pos=lambda: self.center() - QtCore.QPointF(0, 22), parent=self)
self.label.setAlignment(QtCore.Qt.AlignCenter)
#############################################
# INTERFACE
#################################
示例5: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def __init__(self, geometry=QtGui.QPolygonF(),
brush=QtGui.QBrush(QtCore.Qt.NoBrush),
pen=QtGui.QPen(QtCore.Qt.NoPen)):
"""
Initialize the polygon.
:type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
:type brush: QBrush
:type pen: QPen
"""
self._geometry = geometry
self._brush = brush
self._pen = pen
#############################################
# INTERFACE
#################################
示例6: mouseReleaseEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def mouseReleaseEvent(self, event):
""" Stop mouse pan or zoom mode (apply zoom if valid).
"""
QGraphicsView.mouseReleaseEvent(self, event)
scenePos = self.mapToScene(event.pos())
if event.button() == Qt.LeftButton:
self.setDragMode(QGraphicsView.NoDrag)
self.leftMouseButtonReleased.emit(scenePos.x(), scenePos.y())
elif event.button() == Qt.RightButton:
if self.canZoom:
viewBBox = self.zoomStack[-1] if len(self.zoomStack) else self.sceneRect()
selectionBBox = self.scene.selectionArea().boundingRect().intersected(viewBBox)
self.scene.setSelectionArea(QPainterPath()) # Clear current selection area.
if selectionBBox.isValid() and (selectionBBox != viewBBox):
self.zoomStack.append(selectionBBox)
self.updateViewer()
self.setDragMode(QGraphicsView.NoDrag)
self.rightMouseButtonReleased.emit(scenePos.x(), scenePos.y())
示例7: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def __init__(self, parent = None):
super(PlotArea, self).__init__(parent)
self.down_values = []
self.up_values = []
self.max_val = 1
self.x_off = 60
self.offset = 5
self.gap = 8
bold_font = QtGui.QFont()
bold_font.setPointSize(8)
bold_font.setWeight(75)
self.setFont(bold_font)
self.up_path = QtGui.QPainterPath()
self.down_path = QtGui.QPainterPath()
self.setAutoFillBackground(True)
self.wmax = self.width() - self.offset
self.hmax = self.height() - self.offset
示例8: buildPath
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def buildPath(self):
srcPos, tarPos = self.getNodePos()
if self.pathPnt and (self.pathPnt[0]-srcPos).manhattanLength() < 0.05 and (self.pathPnt[1]-tarPos).manhattanLength() < 0.05:
return self.path
self.pathPnt = (srcPos, tarPos)
path = QtGui.QPainterPath()
path.moveTo(srcPos)
dx = tarPos.x() - srcPos.x()
p1 = srcPos + QtCore.QPointF(dx*0.3, 0)
p2 = tarPos + QtCore.QPointF(-dx*0.7, 0)
path.cubicTo(p1,p2,tarPos)
self.curve = QtGui.QPainterPath(path)
self.path = path
from PyQt5.QtGui import QPainterPathStroker
stroker = QPainterPathStroker()
stroker.setWidth(10.0)
self.pathShape = stroker.createStroke(self.path)
return path
示例9: paintEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def paintEvent(self, event):
if not self.data: return
QtWidgets.QFrame.paintEvent(self, event)
painter = QtGui.QPainter()
painter.begin(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
# Draw background
painter.setBrush(QtGui.QBrush(self.bgcolor))
painter.setPen(Qt.NoPen)
painter.drawRoundedRect(self.contentsRect(), 2, 2)
# Draw the Lines
for i in range(len(self.data[0])):
path = None
pen = QtGui.QPen(self.colors[i % len(self.colors)])
for j in range(len(self.data)):
value = self.data[j][i]
prevvalue = self.data[j-1][i]
if value == -1 or prevvalue == -1:
continue
if not self.showzero and value <= 0 and prevvalue <= 0:
continue
x1 = (self.pxperpt * (j - 0.5) + self.pxperpt / 4) - self.offset
x2 = (self.pxperpt * j + self.pxperpt / 4) - self.offset
y1 = self.height() - int((self.height() - 1) * (prevvalue / self.maxvalue))
y2 = self.height() - int((self.height() - 1) * (value / self.maxvalue))
path = path or QtGui.QPainterPath(QtCore.QPointF(x1,y1))
path.cubicTo(x1, y1, x1, y2, x2, y2)
if path:
painter.strokePath(path, pen)
painter.end()
示例10: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def __init__(self, parent):
super(DefinitionsUI, self).__init__()
self.setupUi(self)
self._translate = QtCore.QCoreApplication.translate
self.parent = parent
self.previous_position = None
self.setWindowFlags(
QtCore.Qt.Popup |
QtCore.Qt.FramelessWindowHint)
radius = 15
path = QtGui.QPainterPath()
path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)
try:
mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
self.setMask(mask)
except TypeError: # Required for older versions of Qt
pass
self.definitionView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.app_id = 'bb7a91f9'
self.app_key = 'fefacdf6775c347b52e9efa2efe642ef'
self.root_url = 'https://od-api.oxforddictionaries.com:443/api/v1/inflections/'
self.define_url = 'https://od-api.oxforddictionaries.com:443/api/v1/entries/'
self.pronunciation_mp3 = None
self.okButton.clicked.connect(self.hide)
self.dialogBackground.clicked.connect(self.color_background)
if multimedia_available:
self.pronounceButton.clicked.connect(self.play_pronunciation)
else:
self.pronounceButton.setEnabled(False)
示例11: __init__
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def __init__(self, parent):
super(MetadataUI, self).__init__()
self.setupUi(self)
self._translate = QtCore.QCoreApplication.translate
self.setWindowFlags(
QtCore.Qt.Popup |
QtCore.Qt.FramelessWindowHint)
self.parent = parent
radius = 15
path = QtGui.QPainterPath()
path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)
try:
mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
self.setMask(mask)
except TypeError: # Required for older versions of Qt
pass
self.parent = parent
self.database_path = self.parent.database_path
self.book_index = None
self.book_year = None
self.previous_position = None
self.cover_for_database = None
self.coverView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.coverView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.okButton.clicked.connect(self.ok_pressed)
self.cancelButton.clicked.connect(self.cancel_pressed)
self.dialogBackground.clicked.connect(self.color_background)
self.titleLine.returnPressed.connect(self.ok_pressed)
self.authorLine.returnPressed.connect(self.ok_pressed)
self.yearLine.returnPressed.connect(self.ok_pressed)
self.tagsLine.returnPressed.connect(self.ok_pressed)
示例12: showEvent
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def showEvent(self, event=None):
# TODO
# See what happens when the size of the viewport is smaller
# than the size of the dock
viewport_bottomRight = self.contentView.mapToGlobal(
self.contentView.viewport().rect().bottomRight())
# Dock dimensions
desktop_size = QtWidgets.QDesktopWidget().screenGeometry()
dock_width = desktop_size.width() // 4.5
dock_height = 30
dock_x = viewport_bottomRight.x() - dock_width - 30
dock_y = viewport_bottomRight.y() - 70
self.main_window.active_docks.append(self)
self.setGeometry(dock_x, dock_y, dock_width, dock_height)
# Rounded
radius = 20
path = QtGui.QPainterPath()
path.addRoundedRect(QtCore.QRectF(self.rect()), radius, radius)
try:
mask = QtGui.QRegion(path.toFillPolygon().toPolygon())
self.setMask(mask)
except TypeError: # Required for older versions of Qt
pass
self.animation.start()
示例13: getMask
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def getMask(self, pixmap, x, y, w, h, shape, overlay,
bg=QtCore.Qt.transparent, fg=QtCore.Qt.black, progressive=False):
"""Create a shape mask with the same size of pixmap.
"""
mask = QPixmap(pixmap.width(), pixmap.height())
mask.fill(bg)
path = QtGui.QPainterPath()
if progressive:
progressive = QPixmap(pixmap.width(), pixmap.height())
progressive.fill(QtCore.Qt.transparent)
progressiveMask = QPixmap(self.MASK_PATH)
progressiveMask = progressiveMask.scaled(w, h, QtCore.Qt.IgnoreAspectRatio)
progressivePainter = QtGui.QPainter(progressive)
progressivePainter.drawPixmap(x, y, progressiveMask)
del progressivePainter
fg = QtGui.QBrush(progressive)
painter = QtGui.QPainter(mask)
if shape == self.SHAPE_ELLIPSE:
path.addEllipse(x, y, w, h)
painter.fillPath(path, fg)
elif shape == self.SHAPE_RECT:
painter.fillRect(x, y, w, h, fg)
painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceAtop)
if overlay:
painter.drawPixmap(0, 0, overlay)
return mask
示例14: fillColor
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def fillColor(self, pixmap, painter, roi, param, source):
"""Draw color in roi.
"""
x, y, w, h = roi
if param.shape == self.SHAPE_ELLIPSE:
path = QtGui.QPainterPath()
path.addEllipse(x, y, w, h)
painter.fillPath(path, param.color)
elif param.shape == self.SHAPE_RECT:
painter.fillRect(x, y, w, h, param.color)
示例15: draw_text_n_outline
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPainterPath [as 别名]
def draw_text_n_outline(self, painter: QPainter, x, y, outline_width, outline_blur, text):
outline_color = QColor(config.outline_color)
font = self.font()
text_path = QPainterPath()
if config.R2L_from_B:
text_path.addText(x, y, font, ' ' + r2l(text.strip()) + ' ')
else:
text_path.addText(x, y, font, text)
# draw blur
range_width = range(outline_width, outline_width + outline_blur)
# ~range_width = range(outline_width + outline_blur, outline_width, -1)
for width in range_width:
if width == min(range_width):
alpha = 200
else:
alpha = (max(range_width) - width) / max(range_width) * 200
blur_color = QColor(outline_color.red(), outline_color.green(), outline_color.blue(), alpha)
blur_brush = QBrush(blur_color, Qt.SolidPattern)
blur_pen = QPen(blur_brush, width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
painter.setPen(blur_pen)
painter.drawPath(text_path)
# draw outline
outline_color = QColor(outline_color.red(), outline_color.green(), outline_color.blue(), 255)
outline_brush = QBrush(outline_color, Qt.SolidPattern)
outline_pen = QPen(outline_brush, outline_width, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)
painter.setPen(outline_pen)
painter.drawPath(text_path)
# draw text
color = self.palette().color(QPalette.Text)
painter.setPen(color)
painter.drawText(x, y, text)