Qml Tooltip visibility
Unsolved
QML and Qt Quick
-
I have implemented tooltip inside the chartview.It is hovering all over the mouseArea,even when there is no graph point in the chartview.How to make the tooltip to be visible only when there is a graph point available at that point
ChartView { id:graph_2d2 anchors.fill: parent title: "CPT-graph" backgroundColor: "#011026" ToolTip { id:tooltip2 parent:graph_2d2 visible: false width: 0.24*graph_2d2.width height: 0.08*graph_2d2.height contentItem: Text { id: tootip_text2 text: qsTr("0") font.pixelSize: Math.min(graph_2d2.width / 62, graph_2d2.height / 52) font.bold: true style: Text.Sunken color:"White" horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } background: Rectangle { color:"black" opacity:0.5 border.color:"#21be2b" } } ValueAxis { id: axisX2 min:0 max:100 visible: true reverse: true } ValueAxis { id: yAxis2 min:700// cpt_minX==0?900:cpt_minX max: 3000//cpt_maxX==0?3000:cpt_maxX visible: true } SplineSeries { id:graph2 name: "CPT-output" axisX: yAxis2 axisY: axisX2 style: Qt.SolidLine useOpenGL: true } MouseArea { id:model_area2 anchors.fill: parent hoverEnabled: true propagateComposedEvents: true acceptedButtons: Qt.LeftButton onEntered:{ // Show the tooltip when the mouse enters the graph area tooltip2.visible = true; } onExited:{ tooltip2.visible=false; } onPositionChanged: { if (model_area2.containsMouse) { var mousePos = Qt.point(mouse.x, mouse.y); // Calculate the position of the tooltip tooltip2.x = mouse.x - 0.2*tooltip2.width+25 tooltip2.y = mouse.y - 0.2*tooltip2.height + 25; // Adjust position as needed var val_x = graph_2d2.mapToValue(mousePos,graph2) tootip_text2.text = "Pressure: " +(val_x.x.toFixed(2)) + "\nEncoder_distance: " + (val_x.y.toFixed(2)); } } } }