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);