Gui: ActionGroup - aboutToShow and aboutToHide

==============================================

ActionGroup may integrate a drop down menu (internally a QMenu).

QMenu has signals aboutToShow and aboutToHide, which are called just before showing/hiding the menu.

This commit extends ActionGroup by providing corresponding signals.

An ActionGroup can be added to more than one toolbar and thus creates more than one menu. So, it can theoretically
happen that you have opened a menu and click on another menu. For this reason, the menu is passed as argument:

void aboutToHideMenu(QMenu*);
void aboutToShowMenu(QMenu*);
This commit is contained in:
Abdullah Tahiri
2023-02-09 14:40:36 +01:00
committed by abdullahtahiriyo
parent fe405fcefb
commit 93f646ff25
2 changed files with 23 additions and 1 deletions

View File

@@ -221,7 +221,7 @@ void Action::setToolTip(const QString & text, const QString & title)
_tooltip = text;
_title = title;
_action->setToolTip(createToolTip(text,
title.isEmpty() ? _action->text() : title,
title.isEmpty() ? _action->text() : title,
_action->font(),
_action->shortcut().toString(QKeySequence::NativeText),
command()));
@@ -461,6 +461,14 @@ void ActionGroup::addTo(QWidget *widget)
item->setMenuRole(action()->menuRole());
menu->setTitle(action()->text());
menu->addActions(groupAction()->actions());
QObject::connect(menu, &QMenu::aboutToShow, [this, menu]() {
Q_EMIT aboutToShow(menu);
});
QObject::connect(menu, &QMenu::aboutToHide, [this, menu]() {
Q_EMIT aboutToHide(menu);
});
}
else if (widget->inherits("QToolBar")) {
widget->addAction(action());
@@ -471,6 +479,14 @@ void ActionGroup::addTo(QWidget *widget)
auto menu = new QMenu(tb);
menu->addActions(acts);
tb->setMenu(menu);
QObject::connect(menu, &QMenu::aboutToShow, [this, menu]() {
Q_EMIT aboutToShow(menu);
});
QObject::connect(menu, &QMenu::aboutToHide, [this, menu]() {
Q_EMIT aboutToHide(menu);
});
}
else {
widget->addActions(groupAction()->actions()); // no drop-down