neoscore.interface.qt.q_clipping_path
- class neoscore.interface.qt.q_clipping_path.QClippingPath[source]
Bases:
QGraphicsPathItem
A QGraphicsPathItem extension supporting horizontal path clipping.
Works like a
QGraphicsPathItem
except that it renders a horizontal slice of the path. Rather than rendering the entire path, renders the region starting at a givenclip_start_x
and extending for a givenclip_width
. This rendered region is shifted leftward, so it appears at the path’s root position. This is useful for splitting a path into horizontal chunks and rendering them in different positions, for instance when drawing a staff which appears on multiple lines.clip_start_x
andclip_width
should not take into account scaling. For example if a rendered region of 50 points is required on a path with a scale of 2,clip_width=50
should be passed.While the Qt superclass is mutable, this is intended to be treated immutably. Mutations after instantation will result unexpected behavior. Object mutations at higher abstraction levels should result in new Qt objects created.
Internally, the clipping implementation is rather subtle in how it integrates with Qt’s coordinate and painter systems. The item’s bounding rect is adjusted to match the requested clip region. At render time, the painter translates its coordinate system leftward by the (internally scale-adjusted)
clip_start_x
. The painter’s clip rect is then derived from the item’s bounding rect, but shifted rightward to cancel out the painter’s translation. These actions are all automatically scaled as necessary, since the scale is applied to the QClippingPath, not the painter.Note that clipping behavior does not play well with rotated items, and no API guarantees are currently given about it.
- __init__(qt_path: QPainterPath, clip_start_x: float = 0, clip_width: Optional[float] = None, scale: float = 1, rotation: float = 0, background_brush: Optional[QBrush] = None, defer_geometry_calculation: bool = False, transform_origin: Optional[QPointF] = None)[source]
- Parameters
qt_path – The path for the item. This value should be the same as in
QGraphicsPathItem.__init__()
clip_start_x – The local starting position for the path clipping region. This should not adjust for scaling, as that is performed automatically. Use
0
to render from the start.clip_width – The width of the path clipping region. This should not adjust for scaling, as that is performed automatically. Use
None
to render to the endscale – A scaling factor on the object’s coordinate system.
rotation – Rotation about the path’s origin given in degrees. Rotated path clipping is currently not supported.
background_brush – If given, this will be used to paint over the path’s bounding rect behind the path.
defer_geometry_calculation – If true, this constructor will not automatically calculate the path’s bounding and clipping geometry. When this is set, you must call
update_geometry
when the geometry is finalized. This is useful when post-init modifications immediately alter the geometry, preventing a redundant calculation.transform_origin – The origin point for rotation and scaling transforms
- paint(painter: QPainter, *args, **kwargs)[source]
Paint with automatic clipping.
This is overridden from
QGraphicsPathItem.paint()
- update_geometry()[source]
Recalculate the object’s bounding and clipping rects.
This must be called after any changes affecting these rects, including pen thickness changes.
- static calculate_bounding_rect(bounding_rect: QRectF, clip_start_x: float, clip_width: Optional[float], padding: float) QRectF [source]
Create a QRectF giving the bounding rect for the path.
- Parameters
bounding_rect – The full shape’s bounding rectangle
clip_start_x – The local starting position for the clipping region. Use
None
to render from the start.clip_width – The width of the clipping region. Use
None
to render to the endpadding – Extra area padding to be added to all non-clipped sides of the rect.