Skip to content

Commit e9d39f2

Browse files
committed
owhierarchicalclustering: Inherit SliderLine from QGraphicsWidget
Use palette color as the default pen color.
1 parent 3eeba5e commit e9d39f2

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

Orange/widgets/unsupervised/owhierarchicalclustering.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import numpy as np
88

99
from 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
1414
from AnyQt.QtCore import Qt, QSizeF, QPointF, QRectF, QLineF, QEvent
1515
from AnyQt.QtCore import pyqtSignal as Signal, pyqtSlot as Slot
1616

@@ -891,7 +891,7 @@ def mouseReleaseEvent(self, event):
891891
event.accept()
892892

893893

894-
class SliderLine(QGraphicsObject):
894+
class SliderLine(QGraphicsWidget):
895895
"""A movable slider line."""
896896
valueChanged = Signal(float)
897897

@@ -907,14 +907,10 @@ def __init__(self, parent=None, orientation=Qt.Vertical, value=0.0,
907907
self._length = length
908908
self._min = 0.0
909909
self._max = 1.0
910-
self._line = QLineF() # type: Optional[QLineF]
911-
self._pen = QPen()
910+
self._line: Optional[QLineF] = QLineF()
911+
self._pen: Optional[QPen] = None
912912
super().__init__(parent, **kwargs)
913-
914913
self.setAcceptedMouseButtons(Qt.LeftButton)
915-
self.setPen(make_pen(brush=QColor(50, 50, 50), width=1, cosmetic=False,
916-
style=Qt.DashLine))
917-
918914
if self._orientation == Qt.Vertical:
919915
self.setCursor(Qt.SizeVerCursor)
920916
else:
@@ -929,7 +925,10 @@ def setPen(self, pen: Union[QPen, Qt.GlobalColor, Qt.PenStyle]) -> None:
929925
self.update()
930926

931927
def pen(self) -> QPen:
932-
return QPen(self._pen)
928+
if self._pen is None:
929+
return QPen(self.palette().text(), 1.0, Qt.DashLine)
930+
else:
931+
return QPen(self._pen)
933932

934933
def setValue(self, value: float):
935934
value = min(max(value, self._min), self._max)
@@ -991,6 +990,11 @@ def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None:
991990
self.lineReleased.emit()
992991
event.accept()
993992

993+
def shape(self) -> QPainterPath:
994+
path = QPainterPath()
995+
path.addRect(self.boundingRect())
996+
return path
997+
994998
def boundingRect(self) -> QRectF:
995999
if self._line is None:
9961000
if self._orientation == Qt.Vertical:

0 commit comments

Comments
 (0)