Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Special tooltip does not work in menu



  • Hi,

    I'm trying to display an animated gif as a tooltip, so I've create a widget for that and override
    event function.

    switch (event->type())
        {
        case QEvent::ToolTip:
        {
            QWidget* pWidget = dynamic_cast<QWidget*>(receiver);
            QAction* pAction = dynamic_cast<QAction*>(receiver);
            QHelpEvent *pHelpEvent = static_cast<QHelpEvent *>(event);
            if((pHelpEvent != nullptr) && ((pWidget != nullptr) || (pAction != nullptr)))
            {
                QString sTooltip;
                if(pWidget)
                {
                    sTooltip = pWidget->toolTip();
                }
                else if(pAction)
                {
                    sTooltip = pAction->toolTip();
                }
    
                if(customTooltip(sTooltip, pHelpEvent))
                    return true;
            }
        }
            break;
    
        case QEvent::Leave:
        case QEvent::HoverLeave:
        {
            QWidget* pWidget = dynamic_cast<QWidget*>(receiver);
            QAction* pAction = dynamic_cast<QAction*>(receiver);
            QString sTooltip;
            if(pWidget)
            {
                sTooltip = pWidget->toolTip();
            }
            else if(pAction)
            {
                sTooltip = pAction->toolTip();
            }
    
            if(sTooltip.startsWith("@"))
            {
                m_tooltip.onStop();
            }
        }
            break;
    

    if the reciever tooltip starts with '@', I display a gif otherwise I display the tooltip as usual.
    My problem is:

    • For a QAction in toolbar, my special gif widget is displayed instead of classic tooltip but for a QAction in submenu the classic
      tooltip is displayed, I don't know why.

    Do you have an idea ?
    Thanks (sorry for my english)


Log in to reply