Rajeshwar
Rajeshwar

Reputation: 11651

QToolTip shows up in the wrong cordinates

I currently have a QCustomPlot and I would like to show a QtoolTip on mouseover the component. Here is what I am using. This is my slot.

void CustomPlot::DisplayPlotValue(QMouseEvent* val)
{
     QToolTip::showText(val->pos(), "A tool tip");
}

However the tool tip aappears in the wrong cordinates (its infact out of the form that has my component) . Any suggestion on what i might be doing wrong ?

Upvotes: 1

Views: 513

Answers (2)

cpp
cpp

Reputation: 3801

Use QWidget::mapToGlobal to map coordinates relative to a widget to global coordinates, which are relative to the whole screen:

QToolTip::showText(widget->mapToGlobal(val->pos()), "A tool tip");

where widget is your QWidget.

Upvotes: 1

Jeremy Friesner
Jeremy Friesner

Reputation: 73081

Try this instead:

QToolTip::showText(val->globalPos(), "A tool tip");

Upvotes: 2

Related Questions