setting text to disabled widget action enables the widget
Unsolved
General and Desktop
-
wrote on 30 Jul 2020, 11:08 last edited by user4592357
i have a disabled widget action
the widget is a tool button
when i set text to button's action, the button and action become enabled
why is this?class WidgetAction : public QWidgetAction { public: explicit WidgetAction(QObject* parent = nullptr); QToolButton *getButton() const; protected: QWidget* createWidget(QWidget* parent) override; }; WidgetAction::WidgetAction(QObject* parent /* = nullptr */) : QWidgetAction(parent) { } QToolButton *WidgetAction::getButton() const { auto lstWidgets = createdWidgets(); return !lstWidgets.isEmpty() ? static_cast<QToolButton *>(lstWidgets.at(0)) : nullptr; } QWidget* WidgetAction::createWidget(QWidget* parent) { auto pAction = new QAction(parent); connect(pAction, &QAction::triggered, [=]() { ... }); auto pButton = new QToolButton(parent); pButton->setDefaultAction(pAction); pButton->setAutoRaise(true); pButton->setEnabled(someCondition); return pButton; } // USAGE m_pWidget = new WidgetAction(this); insertAction(pFirstAction, m_pWidget); m_pWidget->setEnabled(false);
later, when i set the text (actually i need to set the tooltip only, but the issue still remains for tooltip too):
auto pButton = m_pWidget->getButton(); if (auto pAction = pButton ? pButton->defaultAction() : nullptr) { pAction->setText(...); }
after this the disabled button becomes enabled.
p.s. the widget action is added to toolbar. -
Hi,
From the looks of it, each time you call getButton, you in fact create a new button.
1/2