ToggleActions: Obey "don't show text" for a particular action toolbar setting

BUGS: 457322
remotes/origin/release/22.08
Albert Astals Cid 4 years ago
parent 01871fdfff
commit 3304038d1d
  1. 15
      part/toggleactionmenu.cpp
  2. 8
      part/toggleactionmenu.h

@ -52,6 +52,7 @@ QWidget *ToggleActionMenu::createWidget(QWidget *parent)
// END QToolButton hack
m_buttons.append(button);
m_originalToolButtonStyle[button] = button->toolButtonStyle();
// Apply other properties to the button.
updateButtons();
@ -74,11 +75,25 @@ void ToggleActionMenu::setDefaultAction(QAction *action)
updateButtons();
}
Qt::ToolButtonStyle ToggleActionMenu::styleFor(QToolButton *button) const
{
Qt::ToolButtonStyle style = m_originalToolButtonStyle[button];
if (style == Qt::ToolButtonTextBesideIcon && priority() < QAction::NormalPriority) {
style = Qt::ToolButtonIconOnly;
}
return style;
}
void ToggleActionMenu::updateButtons()
{
for (QToolButton *button : qAsConst(m_buttons)) {
if (button) {
button->setDefaultAction(this->defaultAction());
// If *this action* is low priority we need to tell the button
// so that it hides the text
button->setToolButtonStyle(styleFor(button));
if (delayed()) { // TODO deprecated interface.
button->setPopupMode(QToolButton::DelayedPopup);

@ -88,6 +88,14 @@ protected:
QPointer<QAction> m_defaultAction;
QList<QPointer<QToolButton>> m_buttons;
QHash<const QToolButton *, Qt::ToolButtonStyle> m_originalToolButtonStyle;
/**
* Returns the aproppriate style for @p button.
* Respects both toolbar settings and settings for this menu action.
*/
Qt::ToolButtonStyle styleFor(QToolButton *button) const;
/**
* Updates the toolbar buttons by setting the current defaultAction() on them.
*

Loading…
Cancel
Save