Automatically associate SvgToolButton widgets to child QMenu. This means we can add a QMenu to a tool button, via the .ui file, and have it be automatically associated.
This commit is contained in:
@@ -139,7 +139,7 @@ add_executable(Bloom
|
|||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/PanelWidget.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/RotatableLabel.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/SvgWidget.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.hpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/SvgToolButton.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/ClickableWidget.cpp
|
||||||
src/Insight/UserInterfaces/InsightWindow/Widgets/ExpandingHeightScrollAreaWidget.hpp
|
src/Insight/UserInterfaces/InsightWindow/Widgets/ExpandingHeightScrollAreaWidget.hpp
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
#include "SvgToolButton.hpp"
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
|
using namespace Bloom::Widgets;
|
||||||
|
|
||||||
|
SvgToolButton::SvgToolButton(QWidget* parent): QToolButton(parent) {
|
||||||
|
this->setButtonWidth(10);
|
||||||
|
this->setButtonHeight(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SvgToolButton::childEvent(QChildEvent* childEvent) {
|
||||||
|
if ((childEvent->added() || childEvent->polished()) && childEvent->child()->isWidgetType()) {
|
||||||
|
/*
|
||||||
|
* If a menu widget has been added as a child to this SvgToolButton, associate the menu with the button
|
||||||
|
* via QToolButton::setMenu().
|
||||||
|
*/
|
||||||
|
auto* menuWidget = qobject_cast<QMenu*>(childEvent->child());
|
||||||
|
if (menuWidget != nullptr && menuWidget != this->menu()) {
|
||||||
|
this->setMenu(menuWidget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QChildEvent>
|
||||||
|
|
||||||
#include "SvgWidget.hpp"
|
#include "SvgWidget.hpp"
|
||||||
|
|
||||||
@@ -17,10 +18,7 @@ namespace Bloom::Widgets
|
|||||||
Q_PROPERTY(int buttonHeight READ getButtonHeight WRITE setButtonHeight DESIGNABLE true)
|
Q_PROPERTY(int buttonHeight READ getButtonHeight WRITE setButtonHeight DESIGNABLE true)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SvgToolButton(QWidget* parent): QToolButton(parent) {
|
explicit SvgToolButton(QWidget* parent);
|
||||||
this->setButtonWidth(10);
|
|
||||||
this->setButtonHeight(10);
|
|
||||||
};
|
|
||||||
|
|
||||||
void setSvgFilePath(const QString& svgFilePath) {
|
void setSvgFilePath(const QString& svgFilePath) {
|
||||||
this->svgWidget->setSvgFilePath(svgFilePath);
|
this->svgWidget->setSvgFilePath(svgFilePath);
|
||||||
@@ -58,6 +56,9 @@ namespace Bloom::Widgets
|
|||||||
return this->buttonHeight;
|
return this->buttonHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void childEvent(QChildEvent* childEvent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SvgWidget* svgWidget = new SvgWidget(this);
|
SvgWidget* svgWidget = new SvgWidget(this);
|
||||||
int buttonWidth = 0;
|
int buttonWidth = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user