77import numpy as np
88
99from AnyQt .QtWidgets import (
10- QGraphicsWidget , QGraphicsObject , QGraphicsScene , QGridLayout , QSizePolicy ,
10+ QGraphicsWidget , QGraphicsScene , QGridLayout , QSizePolicy ,
1111 QAction , QComboBox , QGraphicsGridLayout , QGraphicsSceneMouseEvent
1212)
13- from AnyQt .QtGui import QColor , QPen , QFont , QKeySequence
13+ from AnyQt .QtGui import QPen , QFont , QKeySequence , QPainterPath
1414from AnyQt .QtCore import Qt , QSizeF , QPointF , QRectF , QLineF , QEvent
1515from AnyQt .QtCore import pyqtSignal as Signal , pyqtSlot as Slot
1616
@@ -890,7 +890,7 @@ def mouseReleaseEvent(self, event):
890890 event .accept ()
891891
892892
893- class SliderLine (QGraphicsObject ):
893+ class SliderLine (QGraphicsWidget ):
894894 """A movable slider line."""
895895 valueChanged = Signal (float )
896896
@@ -906,14 +906,10 @@ def __init__(self, parent=None, orientation=Qt.Vertical, value=0.0,
906906 self ._length = length
907907 self ._min = 0.0
908908 self ._max = 1.0
909- self ._line = QLineF () # type : Optional[QLineF]
910- self ._pen = QPen ()
909+ self ._line : Optional [QLineF ] = QLineF ()
910+ self ._pen : Optional [ QPen ] = None
911911 super ().__init__ (parent , ** kwargs )
912-
913912 self .setAcceptedMouseButtons (Qt .LeftButton )
914- self .setPen (make_pen (brush = QColor (50 , 50 , 50 ), width = 1 , cosmetic = False ,
915- style = Qt .DashLine ))
916-
917913 if self ._orientation == Qt .Vertical :
918914 self .setCursor (Qt .SizeVerCursor )
919915 else :
@@ -928,7 +924,10 @@ def setPen(self, pen: Union[QPen, Qt.GlobalColor, Qt.PenStyle]) -> None:
928924 self .update ()
929925
930926 def pen (self ) -> QPen :
931- return QPen (self ._pen )
927+ if self ._pen is None :
928+ return QPen ( self .palette ().text (), 1.0 , Qt .DashLine )
929+ else :
930+ return QPen (self ._pen )
932931
933932 def setValue (self , value : float ):
934933 value = min (max (value , self ._min ), self ._max )
@@ -990,6 +989,11 @@ def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None:
990989 self .lineReleased .emit ()
991990 event .accept ()
992991
992+ def shape (self ) -> QPainterPath :
993+ path = QPainterPath ()
994+ path .addRect (self .boundingRect ())
995+ return path
996+
993997 def boundingRect (self ) -> QRectF :
994998 if self ._line is None :
995999 if self ._orientation == Qt .Vertical :
0 commit comments