From 60a95294858472b65edaf6193235a345640fcd47 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 1 Mar 2021 08:41:49 +0100 Subject: [PATCH] Utils: Allow icons to be used for aspect actions Useful for toggles in tool buttons, as used e.g. in valgrind. Change-Id: I61f5d4ba86d1f39d0071e4c0e37d2447f408a91e Reviewed-by: David Schulz --- src/libs/utils/aspects.cpp | 10 +++++++++- src/libs/utils/aspects.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/aspects.cpp b/src/libs/utils/aspects.cpp index e283d2ff553..6c46de790be 100644 --- a/src/libs/utils/aspects.cpp +++ b/src/libs/utils/aspects.cpp @@ -67,6 +67,7 @@ public: QString m_tooltip; QString m_labelText; QPixmap m_labelPixmap; + QIcon m_icon; QPointer m_label; // Owned by configuration widget QPointer m_action; // Owned by us. @@ -240,6 +241,13 @@ void BaseAspect::setLabelPixmap(const QPixmap &labelPixmap) d->m_label->setPixmap(labelPixmap); } +void BaseAspect::setIcon(const QIcon &icon) +{ + d->m_icon = icon; + if (d->m_action) + d->m_action->setIcon(icon); +} + /*! Returns the current text for the separate label in the visual representation of this aspect. @@ -371,8 +379,8 @@ QWidget *BaseAspect::createConfigWidget() const QAction *BaseAspect::action() { if (!d->m_action) { - //qDebug() << "Creation action for " << labelText() << "with" << value(); d->m_action = new QAction(labelText()); + d->m_action->setIcon(d->m_icon); } return d->m_action; } diff --git a/src/libs/utils/aspects.h b/src/libs/utils/aspects.h index 65e78bce7f1..4e0e3b8f947 100644 --- a/src/libs/utils/aspects.h +++ b/src/libs/utils/aspects.h @@ -97,6 +97,7 @@ public: QString labelText() const; void setLabelText(const QString &labelText); void setLabelPixmap(const QPixmap &labelPixmap); + void setIcon(const QIcon &labelIcon); using ConfigWidgetCreator = std::function; void setConfigWidgetCreator(const ConfigWidgetCreator &configWidgetCreator);