How to detect a mouse click inside a tooltip in Qt?
I have a Qt application in which certain QLabel's display a tooltip if a certain internal condition occurs.
Since the tooltip has a timeout and is hidden by Qt automatically, the tooltip is kept alive by the application by showing the tooltip every 3 seconds (I did not find any mechanism to tell Qt to show a tooltip indefinitely).
The tooltip is displayed until the user clicks on the QLabel itself: the tooltip is not refreshed any more and disappears.
I now have a new requirement that the tooltip should also disappear if the user clicks on the tooltip itself. Is there a signal that is sent when the user clicks on a visible tooltip? Or is it necessary to use some more sophisticated technique?
EDIT
I have checked my code again, here is some extra information.
Qt does detect a mouse click on a tooltip and hides it, but the application immediately shows the tooltip again.
What I would like to do is that Qt informs my code of the mouse-clicked event, so that it stops showing the tooltip again and again. I have two possible solutions in mind, but I do not know if either of them is technically feasible:

Remove tooltip timeout: when a tooltip is shown, it remains visible as long as the user does not click on it. How can I display a tooltip without a timeout in Qt?
Keep the tooltip visible by repeatedly showing it; detect a mouse clicked on the tooltip in order to stop the keep-alive loop. How do I receive a signal when the user clicks on a tooltip?


Under the hood, the actual class that implements the tooltip is a private QLabel-derived class called QTipLabel:
http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/kernel/qtooltip.cpp#line119
There's nothing published in the interface to get at an instance of that class from QToolTip, so intercepting clicks would only be done with some sort of ill-advised hack.
That said: among the events that should "hideTipImmediately" is QEvent::mouseButtonPress...in fact, there's an event filter installed so that any click in the app will hide it:
http://qt.gitorious.org/qt/qt/blobs/4.7/src/gui/kernel/qtooltip.cpp#line325
So if you're not seeing the tooltip disappear when it's being clicked on, there's a bug.  (Clicking on tooltips hides them for me in Qt-based apps under Kubuntu.)

Thanks a lot! I will check if mouse clicks are being filtered somewhere in the application, preventing the tooltip from disappearing.

Note the definition of QToolTip::showText:

void QToolTip::showText ( const QPoint & pos, const QString & text,
  QWidget * w, const QRect & rect )   [static] Shows text as a tool tip,
  with the global position pos as the point of interest. The tool tip
  will be shown with a platform specific offset from this point of
  interest.
If you specify a non-empty rect the tip will be hidden as soon as you
  move your cursor out of this area.
The rect is in the coordinates of the widget you specify with w. If
  the rect is not empty you must specify a widget. Otherwise this
  argument can be 0 but it is used to determine the appropriate screen
  on multi-head systems.
If text is empty the tool tip is hidden. If the text is the same as
  the currently shown tooltip, the tip will not move. You can force
  moving by first hiding the tip with an empty text, and then showing
  the new tip at the new position.

Thus, you can supply the rectangle in which the QToolTip is to be presented.  Then, if what you want to do is close the QToolTip only when the user clicks on it, you can capture mouseButtonPress events as @HostileFork pointed out and then close the tooltip only when the coordinates of the event fall within it.
