VBoxLayout.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "VBoxLayout.h"
  2. #include <QWidget>
  3. VBoxLayout::VBoxLayout(QWidget *parent) : QVBoxLayout(parent) { }
  4. VBoxLayout::~VBoxLayout()
  5. {
  6. removeAllItems();
  7. }
  8. void VBoxLayout::addWidgets(const QList<QWidget *> &widgets, int stretch, Qt::Alignment alignment)
  9. {
  10. for (auto w : widgets) {
  11. addWidget(w, stretch, alignment);
  12. }
  13. }
  14. void VBoxLayout::addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
  15. {
  16. QVBoxLayout::addWidget(widget, stretch, alignment);
  17. m_widgets.append(widget);
  18. widget->show();
  19. }
  20. // remove widget from layout but not delete it
  21. void VBoxLayout::removeWidget(QWidget *widget)
  22. {
  23. QVBoxLayout::removeWidget(widget);
  24. m_widgets.removeAll(widget);
  25. }
  26. // remove widget from layout and delete it
  27. void VBoxLayout::deleteWidget(QWidget *widget)
  28. {
  29. removeWidget(widget);
  30. widget->hide();
  31. widget->deleteLater();
  32. }
  33. void VBoxLayout::removeAllWidget()
  34. {
  35. qDeleteAll(m_widgets);
  36. m_widgets.clear();
  37. }
  38. void VBoxLayout::removeAllItems()
  39. {
  40. QLayoutItem *item;
  41. while ((item = takeAt(0)))
  42. delete item;
  43. }
  44. QList<QWidget *> VBoxLayout::widgets() const
  45. {
  46. return m_widgets;
  47. }