@@ -247,6 +247,33 @@ Rectangle {
247247 textFormat: Text .RichText
248248 }
249249
250+ // Cross-platform hover tracking for tooltips
251+ HoverHandler {
252+ id: sampleChartHoverHandler
253+ onHoveredChanged: {
254+ if (! hovered) {
255+ sampleDataToolTip .visible = false
256+ }
257+ }
258+ onPointChanged: {
259+ if (hovered && sampleChartView .allowHover ) {
260+ const pos = point .position
261+ const pa = sampleChartView .plotArea
262+ if (pos .x >= pa .x && pos .x <= pa .x + pa .width &&
263+ pos .y >= pa .y && pos .y <= pa .y + pa .height ) {
264+ const val = sampleChartView .mapToValue (pos)
265+ sampleDataToolTip .x = pos .x
266+ sampleDataToolTip .y = pos .y
267+ sampleDataToolTip .text = ` <p align="left">x: ${ val .x .toFixed (3 )} <br\> y: ${ val .y .toFixed (3 )} </p>`
268+ sampleDataToolTip .parent = sampleChartView
269+ sampleDataToolTip .visible = true
270+ } else {
271+ sampleDataToolTip .visible = false
272+ }
273+ }
274+ }
275+ }
276+
250277 // Zoom rectangle
251278 Rectangle {
252279 id: sampleRecZoom
@@ -445,8 +472,6 @@ Rectangle {
445472 sampleLine .color = models[k].color
446473 sampleLine .width = 2
447474 sampleLine .useOpenGL = EaGlobals .Vars .useOpenGL
448- // Connect hovered signal for tooltip
449- sampleLine .hovered .connect ((point , state ) => showMainTooltip (sampleChartView, sampleDataToolTip, point, state))
450475 sampleSeries .push (sampleLine)
451476 }
452477
@@ -471,16 +496,5 @@ Rectangle {
471496 }
472497 }
473498
474- // Logic
475- function showMainTooltip (chart , tooltip , point , state ) {
476- if (! chart .allowHover ) {
477- return
478- }
479- const pos = chart .mapToPosition (Qt .point (point .x , point .y ))
480- tooltip .x = pos .x
481- tooltip .y = pos .y
482- tooltip .text = ` <p align="left">x: ${ point .x .toFixed (3 )} <br\> y: ${ point .y .toFixed (3 )} </p>`
483- tooltip .parent = chart
484- tooltip .visible = state
485- }
499+
486500}
0 commit comments