#include "toolBox.h" #include "toolPage.h" #include #include ToolBox::ToolBox(QWidget *parent) : QWidget(parent), m_pContentVBoxLayout(nullptr) { QVBoxLayout *vBoxLayout = new QVBoxLayout(this); vBoxLayout->setContentsMargins(0, 0, 0, 0); //vBoxLayout->addLayout(m_pContentVBoxLayout); //vBoxLayout->addStretch(0); } ToolBox::~ToolBox() { } void ToolBox::addWidget(const QString &title, QWidget *pWidget) { ToolPage *page = new ToolPage(this); page->addWidget(title, pWidget); QBoxLayout* pLayout = dynamic_cast(layout()); pLayout->insertWidget(0,page); pLayout->addStretch(0); m_mapWidget.insert(title,page); } void ToolBox::removeWidget(const QString &title) { bool bExist = m_mapWidget.contains(title); if(bExist) { QWidget *pWidget = m_mapWidget.take(title); if(pWidget) { QBoxLayout* pLayout = dynamic_cast(layout()); ToolPage* toolPage = dynamic_cast(pWidget); if(toolPage) { pLayout->removeWidget(toolPage); delete toolPage; } } } else { //cerr } }