MultiSelectComboBox.h 947 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef MULTISELECTCOMBOBOX_H
  2. #define MULTISELECTCOMBOBOX_H
  3. #include <QComboBox>
  4. #include <QListView>
  5. #include <QStandardItemModel>
  6. class MultiSelectComboBox : public QComboBox
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit MultiSelectComboBox(QWidget *parent = nullptr);
  11. ~MultiSelectComboBox();
  12. void addItem(const QString &text, const QVariant &userData);
  13. void addItem(const QIcon &icon, const QString &text, const QVariant &userData);
  14. void addItems(const QStringList &texts);
  15. QStringList currentText();
  16. QList<int> currentIndex();
  17. void selectItemViewPress(QPoint pos);
  18. protected:
  19. bool eventFilter(QObject *watched, QEvent *event) override;
  20. void showPopup() override;
  21. void hidePopup() override;
  22. signals:
  23. private:
  24. QListView *selectItemView;
  25. QStandardItemModel *selectModel;
  26. QListView *popupView;
  27. QStandardItemModel *popupModel;
  28. bool isPermitHidePopup;
  29. };
  30. #endif // MULTISELECTCOMBOBOX_H