PDA

View Full Version : Extended Tooltip



aamer4yu
23rd July 2008, 11:25
Hi All,
My problem is somewhat related to the tooltip timeout.

I want to display a tooltip as in Visual Studio while debigging -
The tooltip has +/- button and expands more as the + is hovered on.

I understand that this must be custom widget to behave like a tootip.

What I want to achieve is this -
Say i hover a widget, tooltip is shown. Now I want is if the tooltip is shown for more than 1-2 seconds, it should show some detailed tooltip. This detailed tooltip can be stored in whatsThis of a widget. How do I achieve this ??
One solution is making custom widgets. But this will be tedious and inefficient. Also it cant be merged with some existing code easily.

What I did was - installed a event filter on QApplication. In this event I am checking for QEvent::ToolTip. But the problem is - How do I extract the tooltip for the WIDGET/ACTION that is under the mouse ?? If u use toolBar()->addAction(), Qt adds a push button for it. Now in the filter, I am getting focusWidget() as QPushButton, but am not able to extract the tooltip for this pushbutton.

Any ideas how to do it ?

EDIT : I wish there was a function in Qt like QWidget::setToolTip(QToolTip *); And QToolTip class being something like -

class QToolTip
{
QWidget * widgetToShow;
QString tooltip;
QString tooltipDetail;
}


:D

jpn
24th July 2008, 19:17
I'm not sure if the delay of tool tip events can be adjusted but for highly customized tool tips take a look at QxtToolTip (http://doc.libqxt.org/latest/classQxtToolTip.html). ;)

aamer4yu
24th July 2008, 20:11
Well QxtToolTip is what I had in mind,,,, but it wont solve my problem.
It cant be integrated into existing applications.

What I wanted is a way where I could use the exisiting QWidget::toolTip() and QWidget::whatsThis() to get the QSTring, and then display tooltip initiaaly, followed by whatsThis(). This cud be easily integrated in existing applications provided one can extract the QAction under mouse position :)

About the QToolTip format I gave, I wish Qt had something like that without the user being bothered to catch the tooltip event and show himself. It should have been as easy as QWidget::setToolTip(QString), the only thing that we cud pass QWidget instead of QString ;)

wysota
25th July 2008, 15:31
You mean you want it for applications for which you don't have the source code?

aamer4yu
25th July 2008, 18:54
No,,
I want it for applications which I have source code.
But in a way that I need to make minimal changes.

I guess I need to look more into QxtToolTip. How do we get the source for it ? What I understand is, if I use QxtToolTip, I will need to replace all my QWidget::setToolTip() functions. Am I right ??

Also one important question - In my application, most of the tooltip are set for QAction. How do I handle this , if I use QxtTooltip ?? or may be like installing filter :confused:

jpn
25th July 2008, 19:05
I guess I need to look more into QxtToolTip. How do we get the source for it ?
Just download the package from libqxt.org. :)


What I understand is, if I use QxtToolTip, I will need to replace all my QWidget::setToolTip() functions. Am I right ??
Well, QxtToolTip doesn't use QWidget::toolTip property but just catches QEvent::ToolTip for the registered widget and shows the associated tooltip widget.


Also one important question - In my application, most of the tooltip are set for QAction. How do I handle this , if I use QxtTooltip ?? or may be like installing filter :confused:
For example QToolBar provides QToolBar::widgetForAction() so that you can use those individual action widgets to associate tooltip widgets. But as it's mentioned in QxtToolTip docs, it might not be a good idea to flood your application full of complex tooltip widgets. Do you really need complex tooltip widgets for something like actions?

wysota
25th July 2008, 19:12
No,,
I want it for applications which I have source code.
But in a way that I need to make minimal changes.

Apply an event filter on the application object and intercept tooltip events and handle them yourself instead of letting the application do it.

aamer4yu
25th July 2008, 19:16
But as it's mentioned in QxtToolTip docs, it might not be a good idea to flood your application full of complex tooltip widgets.
I agree.


Do you really need complex tooltip widgets for something like actions?
Not really...what I wanted is, show the user simple tooltip, and also give the option to get more detailed tooltip(say, whatsThis). But I wanted simple and detailed tips in one go - either show the detailed one after some delay / or provide some button/icon to expand the tip :)

I was looking for ways to use the already set tooltips and whatsthis in the application. :)

aamer4yu
25th July 2008, 19:28
Apply an event filter on the application object and intercept tooltip events and handle them yourself instead of letting the application do it.
I was doing exactly that :)

But read my FIRST post. I have bolded the problem - How do I extract the tooltip for the WIDGET/ACTION that is under the mouse ??

wysota
25th July 2008, 20:49
That's kind of simple. You get a pointer to the object in the filter. Cast it to a widget using qobject_cast and ask for the tooltip using QWidget::toolTip().

aamer4yu
25th July 2008, 21:13
Correct me if am getting it wrong -

You get a pointer to the object in the filter. Cast it to a widget using qobject_cast and ask for the tooltip using QWidget::toolTip().
I had installed filter on qApp. Wont the pointer to the object be of QApplication type ??

I had tried QApplication::activeWindow and QApplication::focusWidget. But I was not getting the proper pointer. In QApplication::focusWidget I was able to get a pointer to widget, which was of QPushButton type. But I needed a pointer to the action :(

wysota
26th July 2008, 08:59
I had installed filter on qApp. Wont the pointer to the object be of QApplication type ??
That's the whole point - no :) If you examine the docs, you'll notice that they say that by applying an event filter on the application object you can catch events for each and every object handled by the application. I actually never tried it, but if they say so, then I don't see why it shouldn't work. If it turns out to be a bug in the docs, then you can reimplement QCoreApplication::notify to gain total control of the event mechanism. Nevertheless, I'd try the event filter first:


Installing an event filter on QCoreApplication::instance(). Such an event filter is able to process all events for all widgets, so it's just as powerful as reimplementing notify(); furthermore, it's possible to have more than one application-global event filter. Global event filters even see mouse events for disabled widgets.

aamer4yu
26th July 2008, 11:18
Thanks :)

That's the whole point - no

That did the trick. I was under the impression that the QObject* u get in eventFilter, is that of the QOBject on which u had installed the filter. I had installed filter on the QApplication, so I thought I wud get QApplication* pointer :D

But it gives the pointer of the object it is intended for :-)

Now am able to implement what I wanted, jst have to play with position little. and also I can show my custom widgets now :)