WidgetWrapper.hpp
1 #pragma once
2 #include <score/widgets/ClearLayout.hpp>
3 #include <score/widgets/MarginLess.hpp>
4 
5 #include <QGridLayout>
6 #include <QWidget>
7 
14 template <typename Widget>
15 class WidgetWrapper final : public QWidget
16 {
17 public:
18  explicit WidgetWrapper(QWidget* parent)
19  : QWidget{parent}
20  {
21  setContentsMargins(0, 0, 0, 0);
22  m_lay = new score::MarginLess<QGridLayout>{this};
23  }
24 
25  void setWidget(Widget* widg)
26  {
27  if(m_widget)
28  delete m_widget;
29 
30  m_widget = widg;
31 
32  if(m_widget)
33  m_lay->addWidget(m_widget);
34  }
35 
36  Widget* widget() const { return m_widget; }
37 
38 private:
39  QGridLayout* m_lay{};
40  Widget* m_widget{};
41 };
The WidgetWrapper class.
Definition: WidgetWrapper.hpp:16