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 ?


  • Qt Champions 2017

    Hi
    You can subclass the combo and catch event

    bool 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::showText

    Disclaimer. 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.


  • Qt Champions 2017

    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.



  • OK. Make sense to not have tooltip on closed QCOMBOBOX by "default".


  • Qt Champions 2017

    @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.