本文整理汇总了Python中AnyQt.QtGui.QPainterPath.controlPointRect方法的典型用法代码示例。如果您正苦于以下问题:Python QPainterPath.controlPointRect方法的具体用法?Python QPainterPath.controlPointRect怎么用?Python QPainterPath.controlPointRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtGui.QPainterPath
的用法示例。
在下文中一共展示了QPainterPath.controlPointRect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_shapeFromPath
# 需要导入模块: from AnyQt.QtGui import QPainterPath [as 别名]
# 或者: from AnyQt.QtGui.QPainterPath import controlPointRect [as 别名]
def test_shapeFromPath(self):
path = QPainterPath()
path.addRect(10, 10, 20, 20)
pen = QPen(QColor("#FFF"), 2.0)
path = shapeFromPath(path, pen)
self.assertGreaterEqual(area(path.controlPointRect()),
(20 + 2.0) ** 2)
示例2: GraphicsPathObject
# 需要导入模块: from AnyQt.QtGui import QPainterPath [as 别名]
# 或者: from AnyQt.QtGui.QPainterPath import controlPointRect [as 别名]
class GraphicsPathObject(QGraphicsObject):
"""A QGraphicsObject subclass implementing an interface similar to
QGraphicsPathItem, and also adding a positionChanged() signal
"""
positionChanged = Signal([], ["QPointF"])
def __init__(self, parent=None, **kwargs):
super().__init__(parent, **kwargs)
self.setFlag(QGraphicsObject.ItemSendsGeometryChanges)
self.__path = QPainterPath()
self.__brush = QBrush(Qt.NoBrush)
self.__pen = QPen()
self.__boundingRect = None
def setPath(self, path):
"""Set the items `path` (:class:`QPainterPath`).
"""
if not isinstance(path, QPainterPath):
raise TypeError("%r, 'QPainterPath' expected" % type(path))
if self.__path != path:
self.prepareGeometryChange()
# Need to store a copy of object so the shape can't be mutated
# without properly updating the geometry.
self.__path = QPainterPath(path)
self.__boundingRect = None
self.update()
def path(self):
"""Return the items path.
"""
return QPainterPath(self.__path)
def setBrush(self, brush):
"""Set the items `brush` (:class:`QBrush`)
"""
if not isinstance(brush, QBrush):
brush = QBrush(brush)
if self.__brush != brush:
self.__brush = QBrush(brush)
self.update()
def brush(self):
"""Return the items brush.
"""
return QBrush(self.__brush)
def setPen(self, pen):
"""Set the items outline `pen` (:class:`QPen`).
"""
if not isinstance(pen, QPen):
pen = QPen(pen)
if self.__pen != pen:
self.prepareGeometryChange()
self.__pen = QPen(pen)
self.__boundingRect = None
self.update()
def pen(self):
"""Return the items pen.
"""
return QPen(self.__pen)
def paint(self, painter, option, widget=None):
if self.__path.isEmpty():
return
painter.save()
painter.setPen(self.__pen)
painter.setBrush(self.__brush)
painter.drawPath(self.__path)
painter.restore()
def boundingRect(self):
if self.__boundingRect is None:
br = self.__path.controlPointRect()
pen_w = self.__pen.widthF()
self.__boundingRect = br.adjusted(-pen_w, -pen_w, pen_w, pen_w)
return self.__boundingRect
def shape(self):
return shapeFromPath(self.__path, self.__pen)
def itemChange(self, change, value):
if change == QGraphicsObject.ItemPositionHasChanged:
self.positionChanged.emit()
self.positionChanged[QPointF].emit(value)
return super().itemChange(change, value)