Remove tooltip of QAction when add it to QToolBar in Qt -
i added qaction
on qtoolbar
, can't remove tooltip button.
i tried overide event
, eventfilter
using event->type == qt::tooltip
didn't help.
please me.
why happens
when add action on toolbar:
- it creates
qtoolbutton
- calls
qtoolbutton::setdefaultaction
passing action argument. - this method calls
settooltip(action->tooltip());
action->tooltip()
returns whethertooltip
or if tooltip empty returnstext
. you'll have tooltip on button.
what do
using explanation above can think of lots of ways solve problem.
for example, when qtoolbar
created (and possibly shown) use toolbar->findchildren<qtoolbutton*>
find buttons:
foreach(qtoolbutton* button, toolbar->findchildren<qtoolbutton*>()) { button->settooltip(qstring()); }
note: when change text of action, appropriate button recreate tooltip. can use event filter button process tooltip event.
edit: added example:
ui
contains toolbar action.
testwindow::testwindow(qwidget *parent) : qmainwindow(parent) { ui.setupui(this); foreach(qtoolbutton* button, ui.maintoolbar->findchildren<qtoolbutton*>()) { button->settooltip(qstring()); } }
when change action (text, enabling state...) qtoolbutton
updates tooltip. in case need prevent tooltip appearance permanently:
testwindow::testwindow(qwidget *parent) : qmainwindow(parent) { ui.setupui(this); foreach(qtoolbutton* button, ui.maintoolbar->findchildren<qtoolbutton*>()) { button->installeventfilter(this); } } bool testwindow::eventfilter(qobject* o, qevent* e) { if (e->type() == qevent::tooltip) { return true; } return qmainwindow::eventfilter(o, e); }
Comments
Post a Comment