Changeset - 72080817dbc5
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2016-02-28 08:06:53
hy@ozderya.net
fix tooltip crash on toolbutton without default action (for ex; commandwidget remove button)
1 file changed with 11 insertions and 3 deletions:
0 comments (0 inline, 0 general)
tooltipfilter.cpp
Show inline comments
 
@@ -23,32 +23,40 @@
 
#include <QHelpEvent>
 
#include <QToolTip>
 

	
 
#include "tooltipfilter.h"
 

	
 
bool ToolTipFilter::eventFilter(QObject *obj, QEvent *ev)
 
{
 
    if (ev->type() == QEvent::ToolTip && obj->inherits("QToolButton"))
 
    {
 
        // prepare tooltip message
 
        QToolButton* toolButton = (QToolButton*) obj;
 
        QAction* action = toolButton->defaultAction();
 
        QString toolTip = action->toolTip();
 

	
 
        if (toolTip.isEmpty()) return false;
 

	
 
        QString toolTip;
 
        if (action != NULL)
 
        {
 
            toolTip = action->toolTip();
 
        QKeySequence keys = action->shortcut();
 
        if (!keys.isEmpty())
 
        {
 
            toolTip += QString(" <b>[") + keys.toString() + "]</b>";
 
        }
 
        }
 
        else
 
        {
 
            toolTip = toolButton->toolTip();
 
        }
 

	
 
        if (toolTip.isEmpty()) return false;
 

	
 
        // show tooltip message
 
        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(ev);
 
        QToolTip::showText(helpEvent->globalPos(), toolTip);
 
        return true;
 
    }
 
    else
 
    {
 
        return QObject::eventFilter(obj, ev);
 
    }
 
}
0 comments (0 inline, 0 general)