Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfb7c28

Browse files
committed
refactor hover into separate class
1 parent4291ccb commitbfb7c28

File tree

1 file changed

+43
-38
lines changed

1 file changed

+43
-38
lines changed

‎Orange/widgets/utils/slidergraph.py‎

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@
77
fromOrange.widgets.visualize.utils.plotutilsimportPlotWidget
88

99

10+
classInteractiveInfiniteLine(InfiniteLine):
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,**kwargs):
16+
super().__init__(angle=angle,pos=pos,movable=movable,bounds=bounds,**kwargs)
17+
self._normal_pen=None
18+
self._highlight_pen=None
19+
20+
defhoverEvent(self,ev):
21+
"""
22+
Override hoverEvent to provide custom hover behavior.
23+
24+
Parameters
25+
----------
26+
ev : HoverEvent
27+
The hover event from pyqtgraph
28+
"""
29+
ifnothasattr(ev,'isEnter'):
30+
return
31+
32+
ifev.isEnter()andself._highlight_penisnotNone:
33+
self.setPen(self._highlight_pen)
34+
elifev.isExit()andself._normal_penisnotNone:
35+
self.setPen(self._normal_pen)
36+
37+
1038
classSliderGraph(PlotWidget):
1139
"""
1240
An widget graph element that shows a line plot with more sequences. It
@@ -137,58 +165,35 @@ def _plot_cutpoint(self, x):
137165
return
138166
ifself._lineisNone:
139167
# plot interactive vertical line
140-
self._line=InfiniteLine(
168+
self._line=InteractiveInfiniteLine(
141169
angle=90,pos=x,movable=True,
142170
bounds=self.selection_limitifself.selection_limitisnotNone
143171
else (self.x.min(),self.x.max())
144172
)
145173
self._line.setCursor(Qt.SizeHorCursor)
146174

147-
# Set up hover state handling
148-
self._line.hoverEvent=self._handle_hover# Changed from lambda to direct method reference
149-
150-
# Initial pen style
151-
self._line.setPen(mkPen(self.palette().text().color(),width=6,style=Qt.SolidLine,capStyle=Qt.RoundCap))
175+
# Create normal and highlight pens
176+
normal_pen=mkPen(self.palette().text().color(),width=4,style=Qt.SolidLine,capStyle=Qt.RoundCap)
177+
highlight_color=self.palette().highlight().color()
178+
highlight_color.setHsv(
179+
highlight_color.hue(),
180+
min(highlight_color.saturation()+30,255),
181+
max(highlight_color.value()-20,0)
182+
)
183+
highlight_pen=mkPen(highlight_color,width=10,style=Qt.SolidLine,capStyle=Qt.RoundCap)
184+
185+
# Set pens directly
186+
self._line._normal_pen=normal_pen
187+
self._line._highlight_pen=highlight_pen
188+
self._line.setPen(normal_pen)
152189
self._line.sigPositionChanged.connect(self._on_cut_changed)
153190
self.addItem(self._line)
154191
else:
155192
self._line.setValue(x)
156193

157194
self._update_horizontal_lines()
158195

159-
def_handle_hover(self,ev):
160-
"""
161-
Handle hover events for the vertical line.
162-
163-
Parameters
164-
----------
165-
ev : HoverEvent
166-
The hover event from pyqtgraph
167-
"""
168-
ifnothasattr(ev,'isEnter'):# Add check for event type
169-
return
170196

171-
ifev.isEnter():
172-
highlight_color=self.palette().highlight().color()
173-
highlight_color.setHsv(
174-
highlight_color.hue(),
175-
min(highlight_color.saturation()+30,255),
176-
max(highlight_color.value()-20,0)
177-
)
178-
self._line.setPen(mkPen(
179-
highlight_color,
180-
width=10,
181-
style=Qt.SolidLine,
182-
capStyle=Qt.RoundCap
183-
))
184-
elifev.isExit():
185-
# On hover exit: return to normal state
186-
self._line.setPen(mkPen(
187-
self.palette().text().color(),
188-
width=6,
189-
style=Qt.SolidLine,
190-
capStyle=Qt.RoundCap
191-
))
192197

193198
def_plot_horizontal_lines(self):
194199
"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp