aboutsummaryrefslogtreecommitdiff
path: root/multiselectcombobox.h
diff options
context:
space:
mode:
Diffstat (limited to 'multiselectcombobox.h')
-rw-r--r--multiselectcombobox.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/multiselectcombobox.h b/multiselectcombobox.h
new file mode 100644
index 0000000..2478fae
--- /dev/null
+++ b/multiselectcombobox.h
@@ -0,0 +1,41 @@
+#ifndef MULTISELECTCOMBOBOX_H
+#define MULTISELECTCOMBOBOX_H
+
+#include <QComboBox>
+#include <QStandardItemModel>
+#include <QStringList>
+#include <QEvent>
+#include <QLineEdit>
+
+class MultiSelectComboBox : public QComboBox
+{
+ Q_OBJECT
+
+public:
+ explicit MultiSelectComboBox(QWidget *parent = nullptr);
+
+ void addItem(const QString &text);
+ void addItems(const QStringList &texts);
+ QStringList getSelectedItems() const;
+ void setSelectedItems(const QStringList &items);
+ bool allSelected() const;
+ void clear();
+
+signals:
+ void selectionChanged();
+
+protected:
+ void hidePopup() override;
+ bool eventFilter(QObject *watched, QEvent *event) override;
+
+private slots:
+ void onItemPressed(const QModelIndex &index);
+ void updateText();
+
+private:
+ QStandardItemModel *model;
+ bool suppressUpdate;
+ QLineEdit *displayLabel;
+};
+
+#endif // MULTISELECTCOMBOBOX_H