Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import Sequence, overload
- from PySide6.QtCore import QPoint, QPointF, qVersion
- from PySide6.QtGui import QPaintDevice, QPaintEngine, QPainter, QPolygon
- class PaintEngine(QPaintEngine):
- def drawPoints(
- self,
- points: QPointF | QPoint | Sequence[QPointF | QPoint],
- *args: int,
- **kwargs: int,
- ) -> None:
- print("drawPoints:")
- if not isinstance(points, Sequence):
- print("a single point is passed:", points)
- else:
- print(len(points), "points passed", points)
- def drawPolygon(
- self,
- points: QPointF | QPoint | Sequence[QPointF | QPoint],
- *args: QPaintEngine.PolygonDrawMode | int,
- **kwargs: QPaintEngine.PolygonDrawMode | int,
- ) -> None:
- print("drawPolygon:")
- if not isinstance(points, Sequence):
- print("a single point is passed:", points)
- else:
- print(len(points), "points passed", points)
- def begin(self, _dev: QPaintDevice) -> bool:
- return True
- def end(self) -> bool:
- return True
- class PaintDevice(QPaintDevice):
- def __init__(self) -> None:
- super().__init__()
- self._engine: PaintEngine = PaintEngine()
- def paintEngine(self) -> PaintEngine:
- return self._engine
- def metric(self, metric: QPaintDevice.PaintDeviceMetric) -> int:
- if metric == QPaintDevice.PaintDeviceMetric.PdmDevicePixelRatioScaled:
- return super().metric(metric)
- return 1
- print("Qt", qVersion())
- pd: PaintDevice = PaintDevice()
- polygon: Sequence[QPoint | QPointF] = [QPoint(1, 2), QPoint(3, 4)]
- painter: QPainter
- with QPainter(pd) as painter:
- painter.drawPoints(polygon)
- painter.drawPolyline(polygon)
- painter.drawPolyline(QPolygon(polygon))
- painter.drawPolygon(polygon)
- painter.drawPolygon(QPolygon(polygon))
- """
- Expected output:
- ```
- Qt 6.8.2
- drawPoints:
- 2 points passed (PyQt6.QtCore.QPoint(1, 2), PyQt6.QtCore.QPoint(3, 4))
- drawPolygon:
- 2 points passed (PyQt6.QtCore.QPoint(1, 2), PyQt6.QtCore.QPoint(3, 4))
- drawPolygon:
- 2 points passed (PyQt6.QtCore.QPoint(1, 2), PyQt6.QtCore.QPoint(3, 4))
- drawPolygon:
- 2 points passed (PyQt6.QtCore.QPoint(1, 2), PyQt6.QtCore.QPoint(3, 4))
- drawPolygon:
- 2 points passed (PyQt6.QtCore.QPoint(1, 2), PyQt6.QtCore.QPoint(3, 4))
- ```
- Actual output:
- ```
- Qt 6.8.2
- drawPoints:
- a single point is passed: PySide6.QtCore.QPoint(1, 2)
- drawPolygon:
- a single point is passed: PySide6.QtCore.QPoint(1, 2)
- drawPolygon:
- a single point is passed: PySide6.QtCore.QPoint(1, 2)
- drawPolygon:
- a single point is passed: PySide6.QtCore.QPoint(1, 2)
- drawPolygon:
- a single point is passed: PySide6.QtCore.QPoint(1, 2)
- ```
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement