How to display toolTip when mouse on "folded" QComboBox
-
I have a QComboBox (in QDialog) that is not large enough to display the full text of an item when it is "folded". I want to display a tooTip with the full current item text when the mouse is positioned over the QComboBox. In Qt Creator, I tried setting the toolTip property with a constant (just to try) and set mouseTracking on but that does not work. Any idea how to get that done ?
-
Hi
You can subclass the combo and catch eventbool yourcb::event(QEvent* event) {
if (event->type() == QEvent::ToolTip) {
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
QPoint mpos = helpEvent->pos(); // might need mapToGlobal. see doc. i thinks its already translated.
QToolTip::showText( mpos , "Pop My B. up" );Alternative you could use event filter
http://stackoverflow.com/questions/411823/how-do-i-implement-qhoverevent-in-qt
To catch hover and then QToolTip::showTextDisclaimer. Not tried on a combobox. Only custom widget :)
-
Hi,
Thanks for the ideas. I'll give it a try this WE. I'll first have to read about Event Filters which I have not tried up to now.
I was thinking that this toolTip would be sort of "integrated" in Qt Creator since there are parameters for it in the Creator's IHM.
-
It is integrated and for most widgets, you just set the tooltip text and
it will be happy.But as Far as I know, a closed combobox wont display tool tips pr default ,
the way you want it. -
@PALYGAP
Yeah, not tested when it uses its tooltip but
i dont think it was in close state even would be smart.
(you tested that too)If you have time, i suggest trying with eventfilter as such filter is also functional for many other things
so its good pratice.