ctkTreeComboBox.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkTreeComboBox_h
  11. #define __ctkTreeComboBox_h
  12. // Qt includes
  13. #include <QComboBox>
  14. // CTK includes
  15. #include <ctkPimpl.h>
  16. #include "CTKWidgetsExport.h"
  17. /// Description:
  18. /// ComboBox that displays the items as a tree view.
  19. /// See below for a use case:
  20. /// ctkTreeComboBox combo;
  21. /// QStandardItemModel model;
  22. /// model.appendRow(new QStandardItem("Test1"));
  23. /// model.item(0)->appendRow(new QStandardItem("Test1.1"));
  24. /// model.item(0)->appendRow(new QStandardItem("Test1.2"));
  25. /// model.item(0)->appendRow(new QStandardItem("Test1.3"));
  26. /// model.appendRow(new QStandardItem("Test2"));
  27. /// model.appendRow(new QStandardItem("Test3"));
  28. /// combo.setModel(&model);
  29. /// combo.show();
  30. //
  31. class ctkTreeComboBoxPrivate;
  32. class CTK_WIDGETS_EXPORT ctkTreeComboBox : public QComboBox
  33. {
  34. Q_OBJECT
  35. public:
  36. typedef QComboBox Superclass;
  37. explicit ctkTreeComboBox(QWidget* parent = 0);
  38. virtual ~ctkTreeComboBox(){}
  39. virtual bool eventFilter(QObject* object, QEvent* event);
  40. virtual void showPopup();
  41. virtual void hidePopup();
  42. protected:
  43. virtual void paintEvent(QPaintEvent*);
  44. protected slots:
  45. void onExpanded(const QModelIndex&);
  46. void onCollapsed(const QModelIndex&);
  47. private:
  48. CTK_DECLARE_PRIVATE(ctkTreeComboBox);
  49. };
  50. #endif