Skip to content

Instantly share code, notes, and snippets.

@rfletchr
Last active June 18, 2024 01:53
Show Gist options
  • Save rfletchr/f1e57f52e980b073f8598e9d7472ef43 to your computer and use it in GitHub Desktop.
Save rfletchr/f1e57f52e980b073f8598e9d7472ef43 to your computer and use it in GitHub Desktop.
A subclass of QtWidgets.QGraphicsDropShadowEffect which accounts for view scaling.
from PySide6 import QtWidgets, QtCore
class SceneSpaceShadowEffect(QtWidgets.QGraphicsDropShadowEffect):
"""
A drop shadow effect which takes the scene space size into account.
"""
def __init__(self, parent=None):
super().__init__(parent=parent)
self._blur_radius = super().blurRadius()
self._offset = super().offset()
def blurRadius(self):
return self._blur_radius
def offset(self):
return self._offset
def setBlurRadius(self, value: float):
self._blur_radius = value
def setOffset(self, value: QtCore.QPointF):
self._offset = value
def draw(self, painter):
super().setOffset(self._offset * painter.transform().m11())
super().setBlurRadius(self._blur_radius * painter.transform().m11())
super().draw(painter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment