22 QStandardItemModel* model;
25 MultiList(QWidget* parent = 0) : QComboBox(parent) {
29 model =
new QStandardItemModel;
32 connect(model, SIGNAL(itemChanged(QStandardItem*)),
this, SLOT(
slotUpdate()));
36 int row = model->rowCount();
37 QStandardItem* item =
new QStandardItem();
39 item->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
40 item->setData(Qt::Unchecked, Qt::CheckStateRole);
41 model->setItem(row, 0, item);
42 this->setModel(model);
46 for (
int i = 0; i < texts.count(); i++) {
52 QStringList checkedItems;
54 for (
int i = 0; i < model->rowCount(); i++) {
55 if (model->item(i, 0)->checkState() == Qt::Checked) {
56 checkedItems << model->item(i, 0)->text();
64 for (
int i = 0; i < items.count(); i++) {
65 int index = findText(items.at(i));
68 model->item(index)->setData(Qt::Checked, Qt::CheckStateRole);
77 lineEdit()->setText(displayText);
83 for (
int i = 0; i < model->rowCount(); i++) {
84 if (model->item(i, 0)->checkState() == Qt::Checked) {
85 displayText = displayText + model->item(i, 0)->text() +
"; ";
Definition: Multilist.h:17
void addItems(const QStringList &texts)
Definition: Multilist.h:45
void addItem(const QString &text)
Definition: Multilist.h:35
QStringList getCheckedItems() const
Definition: Multilist.h:51
void slotUpdateText()
Definition: Multilist.h:76
MultiList(QWidget *parent=0)
Definition: Multilist.h:25
void setCheckedItems(const QStringList &items)
Definition: Multilist.h:63
void slotUpdate()
Definition: Multilist.h:80