PainterPath
Base classes
| Name |
Children |
Inherits |
QPainterPath PySide6.QtGui QPainterPath(self, /) -> None |
|
|
â‹” Inheritance diagram
graph TD
1866181256["gui.PainterPath"]
3328378269["QtGui.QPainterPath"]
37984305["Shiboken.Object"]
2751680898["builtins.object"]
3328378269 --> 1866181256
37984305 --> 3328378269
2751680898 --> 37984305
🛈 DocStrings
Bases: QPainterPath
Source code in prettyqt/gui/painterpath.py
| class PainterPath(QtGui.QPainterPath):
def __len__(self):
return self.elementCount()
def __getitem__(self, index: int) -> QtGui.QPainterPath.Element:
return self.elementAt(index)
def __iter__(self) -> Iterator[QtGui.QPainterPath.Element]:
return iter(self.elementAt(i) for i in range(self.elementCount()))
def __setitem__(self, index: int, value: tuple[int, int]):
self.setElementPositionAt(index, *value)
def __iadd__(self, other):
if not isinstance(
other,
core.QRect
| core.QRectF
| QtGui.QPolygonF
| QtGui.QPainterPath
| QtGui.QRegion,
):
raise TypeError(other)
self.add(other)
return self
def add(
self,
other: core.QRect
| core.QRectF
| QtGui.QPolygonF
| QtGui.QPainterPath
| QtGui.QRegion,
):
match other:
case QtGui.QPolygonF():
self.addPolygon(other)
case QtGui.QPainterPath():
self.addPath(other)
case core.QRect():
self.addRect(core.QRectF(other))
case core.QRectF():
self.addRect(other)
case QtGui.QRegion():
self.addRegion(other)
def __bool__(self):
return not self.isEmpty()
def __contains__(self, item: core.QPointF | core.QRectF | QtGui.QPainterPath):
return self.contains(item)
def add_rect(self, rect: datatypes.RectType | datatypes.RectFType):
self.addRect(datatypes.to_rectf(rect))
def set_fill_rule(self, rule: constants.FillRuleStr | constants.FillRule):
"""Set fill rule.
Args:
rule: fill rule to use
"""
self.setFillRule(constants.FILL_RULE.get_enum_value(rule))
def get_fill_rule(self) -> constants.FillRuleStr:
"""Return current fill rule.
Returns:
fill rule
"""
return constants.FILL_RULE.inverse[self.fillRule()]
def get_bounding_rect(self) -> core.RectF:
return core.RectF(self.boundingRect())
def get_simplified(self) -> PainterPath:
return PainterPath(self.simplified())
def to_reversed(self) -> PainterPath:
return PainterPath(self.toReversed())
@classmethod
def create_star(cls, size: int):
path = cls()
star_center_x = size / 2
star_center_y = size / 2
radius_outer = size * 0.35
golden_ratio = (1 + math.sqrt(5)) / 2
radius_inner = radius_outer / (1 + golden_ratio)
theta_start = math.pi / 2
theta_inc = (2 * math.pi) / 10
for n in range(11):
theta = theta_start + (n * theta_inc)
theta = theta % (2 * math.pi)
if n % 2 == 0:
x = radius_outer * math.cos(theta)
y = radius_outer * math.sin(theta)
else:
x = radius_inner * math.cos(theta)
y = radius_inner * math.sin(theta)
x_adj = star_center_x - x
y_adj = star_center_y - y + 3
if n == 0:
path.moveTo(x_adj, y_adj)
else:
path.lineTo(x_adj, y_adj)
return path
|
get_fill_rule() -> constants.FillRuleStr
Return current fill rule.
Source code in prettyqt/gui/painterpath.py
| def get_fill_rule(self) -> constants.FillRuleStr:
"""Return current fill rule.
Returns:
fill rule
"""
return constants.FILL_RULE.inverse[self.fillRule()]
|
set_fill_rule(rule: constants.FillRuleStr | constants.FillRule)
Set fill rule.
Parameters:
| Name |
Type |
Description |
Default |
rule
|
FillRuleStr | FillRule
|
|
required
|
Source code in prettyqt/gui/painterpath.py
| def set_fill_rule(self, rule: constants.FillRuleStr | constants.FillRule):
"""Set fill rule.
Args:
rule: fill rule to use
"""
self.setFillRule(constants.FILL_RULE.get_enum_value(rule))
|
:fa-brands-github: Show source on GitHub