Skip to content

Commit

Permalink
owhierarchicalclustering: Inherit SliderLine from QGraphicsWidget
Browse files Browse the repository at this point in the history
Use palette color as the default pen color.
  • Loading branch information
ales-erjavec committed Jan 10, 2022
1 parent 3eeba5e commit e9d39f2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions Orange/widgets/unsupervised/owhierarchicalclustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import numpy as np

from AnyQt.QtWidgets import (
QGraphicsWidget, QGraphicsObject, QGraphicsScene, QGridLayout, QSizePolicy,
QGraphicsWidget, QGraphicsScene, QGridLayout, QSizePolicy,
QAction, QComboBox, QGraphicsGridLayout, QGraphicsSceneMouseEvent
)
from AnyQt.QtGui import QColor, QPen, QFont, QKeySequence
from AnyQt.QtGui import QPen, QFont, QKeySequence, QPainterPath
from AnyQt.QtCore import Qt, QSizeF, QPointF, QRectF, QLineF, QEvent
from AnyQt.QtCore import pyqtSignal as Signal, pyqtSlot as Slot

Expand Down Expand Up @@ -891,7 +891,7 @@ def mouseReleaseEvent(self, event):
event.accept()


class SliderLine(QGraphicsObject):
class SliderLine(QGraphicsWidget):
"""A movable slider line."""
valueChanged = Signal(float)

Expand All @@ -907,14 +907,10 @@ def __init__(self, parent=None, orientation=Qt.Vertical, value=0.0,
self._length = length
self._min = 0.0
self._max = 1.0
self._line = QLineF() # type: Optional[QLineF]
self._pen = QPen()
self._line: Optional[QLineF] = QLineF()
self._pen: Optional[QPen] = None
super().__init__(parent, **kwargs)

self.setAcceptedMouseButtons(Qt.LeftButton)
self.setPen(make_pen(brush=QColor(50, 50, 50), width=1, cosmetic=False,
style=Qt.DashLine))

if self._orientation == Qt.Vertical:
self.setCursor(Qt.SizeVerCursor)
else:
Expand All @@ -929,7 +925,10 @@ def setPen(self, pen: Union[QPen, Qt.GlobalColor, Qt.PenStyle]) -> None:
self.update()

def pen(self) -> QPen:
return QPen(self._pen)
if self._pen is None:
return QPen(self.palette().text(), 1.0, Qt.DashLine)
else:
return QPen(self._pen)

def setValue(self, value: float):
value = min(max(value, self._min), self._max)
Expand Down Expand Up @@ -991,6 +990,11 @@ def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None:
self.lineReleased.emit()
event.accept()

def shape(self) -> QPainterPath:
path = QPainterPath()
path.addRect(self.boundingRect())
return path

def boundingRect(self) -> QRectF:
if self._line is None:
if self._orientation == Qt.Vertical:
Expand Down

0 comments on commit e9d39f2

Please sign in to comment.