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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user