3

I want to show tool tip on the QGLWidget but i must the call; QToolTip::showText(pos, "Message", qglwidgetPtr, rect(), 5000); in another class.

So, tooltip disappears after releasing the mouse button. If I don't release it, the tooltip disappears after that 5000 msecs. I do not understand the disappear problem. I think it could be trigger disappear QGL widget paint event but i'm not sure.

tilt_y
  • 119
  • 1
  • 1
  • 4

1 Answers1

0

First of all, let's understand what is the reasion of the problem. Tooltips should hide when user move the mouse cursor not above them. So, when you release the mouse button somewhere else, your OS catches a mouse event not above the tooltip (not near starting point of that tooltip), so it hides the tooltip.

So, my solution is following: create QTimer and show your tooltip few times per second as long as you need (5 seconds). You can do it, because in the documentation it is said that

If the text is the same as the currently shown tooltip, the tip will not move

(i.e. it is ok to call showText many times with the same text)

To create the timer you can use this code:

QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
timer->start(100); // ten times per second

And inside the body of the update() function you can compare current time and the time of first showing of this tooltip, and to show your tooltip if it is still necessary (i.e. if it is shown less than 5 seconds).

howLongShown = curTime - startTime; // startTime here is the moment of first showing of the tooltip
if (howLongShown < 5000)
  QToolTip::showText(pos, "Message", qglwidgetPtr, rect(), 5000 - howLongShown);
Ilya
  • 4,583
  • 4
  • 26
  • 51
  • Actually I thought to solve with timer but i did not want it. Now i think no other choice. Create timer like you do and solve the problem. Thanks – tilt_y Jun 17 '16 at 15:10