Skip to content

Commit d1f560e

Browse files
authored
Merge pull request #2821 from ales-erjavec/canvas/annotation-shadow-hidpi
[FIX] canvas/annotationitem: Use separate item for shadow base
2 parents 11c27f6 + 7147a5d commit d1f560e

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

Orange/canvas/canvas/items/annotationitem.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
QGraphicsDropShadowEffect, QMenu, QAction, QActionGroup
1212
)
1313
from AnyQt.QtGui import (
14-
QPainterPath, QPainterPathStroker, QPolygonF, QColor, QPen
14+
QPainterPath, QPainterPathStroker, QPolygonF, QColor, QPen, QBrush
1515
)
1616
from AnyQt.QtCore import (
1717
Qt, QPointF, QSizeF, QRectF, QLineF, QEvent, QMetaObject, QT_VERSION
@@ -699,22 +699,32 @@ def __init__(self, parent=None, line=None, **kwargs):
699699
if line is None:
700700
line = QLineF(0, 0, 20, 0)
701701

702-
self.__line = line
702+
self.__line = QLineF(line)
703703
self.__color = QColor(Qt.red)
704-
self.__arrowItem = ArrowItem(self)
705-
self.__arrowItem.setLine(line)
706-
self.__arrowItem.setBrush(self.__color)
707-
self.__arrowItem.setPen(QPen(Qt.NoPen))
708-
self.__arrowItem.setArrowStyle(ArrowItem.Concave)
709-
self.__arrowItem.setLineWidth(5)
704+
# An item with the same shape as this arrow, stacked behind this
705+
# item as a source for QGraphicsDropShadowEffect. Cannot attach
706+
# the effect to this item directly as QGraphicsEffect makes the item
707+
# non devicePixelRatio aware.
708+
self.__arrowShadowBase = ArrowItem(self, line=line)
709+
self.__arrowShadowBase.setPen(Qt.NoPen) # no pen -> slightly thinner
710+
self.__arrowShadowBase.setBrush(QBrush(self.__color))
711+
self.__arrowShadowBase.setArrowStyle(ArrowItem.Concave)
712+
self.__arrowShadowBase.setLineWidth(5)
710713

711714
self.__shadow = QGraphicsDropShadowEffect(
712715
blurRadius=5, offset=QPointF(1.0, 2.0),
713716
)
714717

715-
self.__arrowItem.setGraphicsEffect(self.__shadow)
718+
self.__arrowShadowBase.setGraphicsEffect(self.__shadow)
716719
self.__shadow.setEnabled(True)
717720

721+
# The 'real' shape item
722+
self.__arrowItem = ArrowItem(self, line=line)
723+
self.__arrowItem.setBrush(self.__color)
724+
self.__arrowItem.setPen(QPen(self.__color))
725+
self.__arrowItem.setArrowStyle(ArrowItem.Concave)
726+
self.__arrowItem.setLineWidth(5)
727+
718728
self.__autoAdjustGeometry = True
719729

720730
def setAutoAdjustGeometry(self, autoAdjust):
@@ -742,7 +752,7 @@ def setLine(self, line):
742752
Set the arrow base line (a `QLineF` in object coordinates).
743753
"""
744754
if self.__line != line:
745-
self.__line = line
755+
self.__line = QLineF(line)
746756

747757
# local item coordinate system
748758
geom = self.geometry().translated(-self.pos())
@@ -764,6 +774,7 @@ def setLine(self, line):
764774
diff = geom.topLeft()
765775
line = QLineF(line.p1() - diff, line.p2() - diff)
766776
self.__arrowItem.setLine(line)
777+
self.__arrowShadowBase.setLine(line)
767778
self.__line = line
768779

769780
# parent item coordinate system
@@ -795,6 +806,7 @@ def setLineWidth(self, lineWidth):
795806
Set the arrow line width.
796807
"""
797808
self.__arrowItem.setLineWidth(lineWidth)
809+
self.__arrowShadowBase.setLineWidth(lineWidth)
798810

799811
def lineWidth(self):
800812
"""
@@ -846,11 +858,14 @@ def __updateStyleState(self):
846858
pen = QPen(QColor(96, 158, 215), Qt.DashDotLine)
847859
pen.setWidthF(1.25)
848860
pen.setCosmetic(True)
849-
self.__shadow.setColor(pen.color().darker(150))
861+
shadow = pen.color().darker(150)
850862
else:
851863
color = self.__color
852-
pen = QPen(Qt.NoPen)
853-
self.__shadow.setColor(QColor(63, 63, 63, 180))
864+
pen = QPen(color)
865+
shadow = QColor(63, 63, 63, 180)
866+
867+
self.__arrowShadowBase.setBrush(color)
868+
self.__shadow.setColor(shadow)
854869

855870
self.__arrowItem.setBrush(color)
856871
self.__arrowItem.setPen(pen)

0 commit comments

Comments
 (0)