本文整理汇总了Python中PyQt5.QtGui.QPolygon方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QPolygon方法的具体用法?Python QtGui.QPolygon怎么用?Python QtGui.QPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui
的用法示例。
在下文中一共展示了QtGui.QPolygon方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: selectpoly_copy
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygon [as 别名]
def selectpoly_copy(self):
"""
Copy a polygon region from the current image, returning it.
Create a mask for the selected area, and use it to blank
out non-selected regions. Then get the bounding rect of the
selection and crop to produce the smallest possible image.
:return: QPixmap of the copied region.
"""
self.timer_cleanup()
pixmap = self.pixmap().copy()
bitmap = QBitmap(*CANVAS_DIMENSIONS)
bitmap.clear() # Starts with random data visible.
p = QPainter(bitmap)
# Construct a mask where the user selected area will be kept,
# the rest removed from the image is transparent.
userpoly = QPolygon(self.history_pos + [self.current_pos])
p.setPen(QPen(Qt.color1))
p.setBrush(QBrush(Qt.color1)) # Solid color, Qt.color1 == bit on.
p.drawPolygon(userpoly)
p.end()
# Set our created mask on the image.
pixmap.setMask(bitmap)
# Calculate the bounding rect and return a copy of that region.
return pixmap.copy(userpoly.boundingRect())
# Select rectangle events
示例2: clip
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygon [as 别名]
def clip(self, p, w, h):
"""Clip image before painting
Parameters
----------
p :
QPainter object used for painting
w :
image width
h :
image height
Returns
-------
"""
if self.clip_mask is not None:
if isinstance(self.clip_mask, float): # centered circle
a = QRegion(
w / 2 - self.clip_mask * w,
h / 2 - self.clip_mask * h,
self.clip_mask * w * 2,
self.clip_mask * h * 2,
type=QRegion.Ellipse,
)
p.setClipRegion(a)
elif isinstance(self.clip_mask[0], tuple): # polygon
points = [QPoint(int(w * x), int(h * y)) for (x, y) in self.clip_mask]
p.setClipRegion(QRegion(QPolygon(points)))
else:
p.setClipRect(
self.clip_mask[0] * w,
self.clip_mask[1] * h,
self.clip_mask[2] * w,
self.clip_mask[3] * h,
)
示例3: draw_block
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygon [as 别名]
def draw_block(self, p, point, w, h):
# Painting settings:
p.setPen(Qt.NoPen)
p.setRenderHint(QPainter.Antialiasing)
# Here for changing black with another color (to be debugged)
# p.setBrush(QBrush(QColor(*self.color_2)))
# # p.drawRect(QRect(-1, -1, (w + 2)*1.5, (h + 2)*1.5))
p.setBrush(QBrush(QColor(*self.color)))
# To draw a windmill, a set of consecutive triangles will be painted:
mid_x = int(w / 2) # calculate image center
mid_y = int(h / 2)
# calculate angles for each triangle:
angles = np.arange(0, np.pi * 2, (np.pi * 2) / self.n_arms)
angles += np.pi / 2 + np.pi / (2 * self.n_arms)
# angular width of the white arms, by default equal to dark ones
size = np.pi / self.n_arms
# radius of triangles (much larger than frame)
rad = (w ** 2 + h ** 2) ** (1 / 2)
# loop over angles and draw consecutive triangles
for deg in np.array(angles):
polyg_points = [
QPoint(mid_x, mid_y),
QPoint(int(mid_x + rad * np.cos(deg)), int(mid_y + rad * np.sin(deg))),
QPoint(
int(mid_x + rad * np.cos(deg + size)),
int(mid_y + rad * np.sin(deg + size)),
),
]
polygon = QPolygon(polyg_points)
p.drawPolygon(polygon)
示例4: draw_connection_line
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygon [as 别名]
def draw_connection_line(painter, x1, y1, x2, y2, h1, h2):
# Account for list view headers.
y1 += h1
y2 += h2
# Invisible output ports don't get a connecting dot.
if y1 > h1:
painter.drawLine(x1, y1, x1 + 4, y1)
# Setup control points
spline = QPolygon(4)
cp = int((x2 - x1 - 8) * 0.4)
spline.setPoints(x1 + 4, y1,
x1 + 4 + cp, y1,
x2 - 4 - cp, y2,
x2 - 4, y2)
# The connection line
path = QPainterPath()
path.moveTo(spline.at(0))
path.cubicTo(spline.at(1), spline.at(2), spline.at(3))
painter.strokePath(path, painter.pen())
# painter.drawLine(x1 + 4, y1, x2 - 4, y2)
# Invisible input ports don't get a connecting dot.
if y2 > h2:
painter.drawLine(x2 - 4, y2, x2, y2)
示例5: paint
# 需要导入模块: from PyQt5 import QtGui [as 别名]
# 或者: from PyQt5.QtGui import QPolygon [as 别名]
def paint(self, p, w, h):
p.setPen(Qt.NoPen)
p.setBrush(QBrush(QColor(*self.color)))
p.setRenderHint(QPainter.Antialiasing)
points = []
if self.left:
dtheta = np.pi / 2
else:
dtheta = -np.pi / 2
theta = self.theta
sx = (
self.x
+ h / 2 * np.cos(theta)
+ self.center_dist * np.cos(theta - np.pi / 2)
)
sy = (
self.y
+ h / 2 * np.sin(theta)
+ self.center_dist * np.sin(theta - np.pi / 2)
)
points.append(QPoint(sx, sy))
theta += dtheta
sx += w * np.cos(theta)
sy += w * np.sin(theta)
points.append(QPoint(sx, sy))
theta += dtheta
sx += h * np.cos(theta)
sy += h * np.sin(theta)
points.append(QPoint(sx, sy))
theta += dtheta
sx += w * np.cos(theta)
sy += w * np.sin(theta)
points.append(QPoint(sx, sy))
theta += dtheta
sx += h * np.cos(theta)
sy += h * np.sin(theta)
points.append(QPoint(sx, sy))
poly = QPolygon(points)
p.drawPolygon(poly)