|
7 | 7 | from Orange.widgets.visualize.utils.plotutils import PlotWidget |
8 | 8 |
|
9 | 9 |
|
| 10 | +class InteractiveInfiniteLine(InfiniteLine): # pylint: disable=abstract-method |
| 11 | + """ |
| 12 | + A subclass of InfiniteLine that provides custom hover behavior. |
| 13 | + """ |
| 14 | + |
| 15 | + def __init__(self, angle=90, pos=None, movable=False, bounds=None, |
| 16 | + normal_pen=None, highlight_pen=None, **kwargs): |
| 17 | + super().__init__(angle=angle, pos=pos, movable=movable, bounds=bounds, **kwargs) |
| 18 | + self._normal_pen = normal_pen |
| 19 | + self._highlight_pen = highlight_pen |
| 20 | + self.setPen(normal_pen) |
| 21 | + |
| 22 | + def hoverEvent(self, ev): |
| 23 | + """ |
| 24 | + Override hoverEvent to provide custom hover behavior. |
| 25 | +
|
| 26 | + Parameters |
| 27 | + ---------- |
| 28 | + ev : HoverEvent |
| 29 | + The hover event from pyqtgraph |
| 30 | + """ |
| 31 | + |
| 32 | + if ev.isEnter() and self._highlight_pen is not None: |
| 33 | + self.setPen(self._highlight_pen) |
| 34 | + elif ev.isExit() and self._normal_pen is not None: |
| 35 | + self.setPen(self._normal_pen) |
| 36 | + |
| 37 | + |
10 | 38 | class SliderGraph(PlotWidget): |
11 | 39 | """ |
12 | 40 | An widget graph element that shows a line plot with more sequences. It |
@@ -136,14 +164,23 @@ def _plot_cutpoint(self, x): |
136 | 164 | self._line = None |
137 | 165 | return |
138 | 166 | if self._line is None: |
139 | | - # plot interactive vertical line |
140 | | - self._line = InfiniteLine( |
| 167 | + normal_pen = mkPen( |
| 168 | + self.palette().text().color(), width=4, |
| 169 | + style=Qt.SolidLine, capStyle=Qt.RoundCap |
| 170 | + ) |
| 171 | + highlight_pen = mkPen( |
| 172 | + self.palette().link().color(), width=4, |
| 173 | + style=Qt.SolidLine, capStyle=Qt.RoundCap |
| 174 | + ) |
| 175 | + |
| 176 | + self._line = InteractiveInfiniteLine( |
141 | 177 | angle=90, pos=x, movable=True, |
142 | 178 | bounds=self.selection_limit if self.selection_limit is not None |
143 | | - else (self.x.min(), self.x.max()) |
| 179 | + else (self.x.min(), self.x.max()), |
| 180 | + normal_pen=normal_pen, |
| 181 | + highlight_pen=highlight_pen |
144 | 182 | ) |
145 | 183 | self._line.setCursor(Qt.SizeHorCursor) |
146 | | - self._line.setPen(mkPen(self.palette().text().color(), width=2)) |
147 | 184 | self._line.sigPositionChanged.connect(self._on_cut_changed) |
148 | 185 | self.addItem(self._line) |
149 | 186 | else: |
|
0 commit comments