Reputation: 273
I added a QAction
on a QToolBar
, but I can't remove a tooltip from the button.
I tried to overide event
, eventfilter
using event->type == Qt::Tooltip
but it didn't help.
Please help me.
Upvotes: 1
Views: 3492
Reputation: 4344
When you add an action on a toolbar:
QToolButton
QToolButton::setDefaultAction
passing the action as an argument.setToolTip(action->toolTip());
action->toolTip()
returns whether tooltip
or if the tooltip is empty it returns text
. Thus you'll always have some tooltip on the button.Using the explanation above you can think of lots of ways to solve the problem.
For example, when QToolbar
is created (and possibly shown) use toolbar->findChildren<QToolButton*>
to find the buttons:
foreach(QToolButton* button, toolbar->findChildren<QToolButton*>())
{
button->setToolTip(QString());
}
Note: when you change a text of an action, the appropriate button will recreate the tooltip. You can use an event filter for a button to process the tooltip event.
EDIT: added an example:
Ui
contains a toolbar with an action.
testwindow::testwindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
foreach(QToolButton* button, ui.mainToolBar->findChildren<QToolButton*>())
{
button->setToolTip(QString());
}
}
When you change an action (text, enabling state...) a QToolButton
updates a tooltip. In this case you need to prevent the 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);
}
Upvotes: 4