Solved Black list of QCombobox items
-
Is the list of options in the combobox fixed or does it change from cell to cell?
-
For each row is different.
This is a product list which has to set different label. -
How does each row know what list to show?
-
From configuration.
It's a global object.For each combobx the list of items will be the same, but which item is set it depends on configuration.
Each row represents one product from configuration. -
@Kaluss said in Black list of QCombobox items:
For each combobx the list of items will be the same
That's what I wanted to know
#include <QStringListModel> #include <QComboBox> #include <QStyledItemDelegate> class ComboDelegate : public QStyledItemDelegate{ Q_DISABLE_COPY(ComboDelegate) public: ComboDelegate(QObject* parent = Q_NULLPTR) : QStyledItemDelegate(parent) , m_options(new QStringListModel(this)) {} QStringList options() const {return m_options->stringList();} void setOptions(const QStringList& opt){ m_options->setStringList(opt); } virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE{ Q_UNUSED(option); Q_UNUSED(index); QComboBox* editor = new QComboBox(parent); editor->setModel(m_options); return editor; } virtual void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE{ QComboBox* cbEditor = qobject_cast<QComboBox*>(editor); Q_ASSERT(cbEditor); cbEditor->setCurrentIndex(cbEditor->findText(index.data().toString())); } virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const Q_DECL_OVERRIDE{ QComboBox* cbEditor = qobject_cast<QComboBox*>(editor); Q_ASSERT(cbEditor); model->setData(index,cbEditor->currentText()); } private: QStringListModel* m_options; };
-
Hi,
I get the error:
qt has no member named 'stOptions'.Its shouldn't be there just options?
If I change it to options I get:
error: no matching function for call to 'ComboDelegate::options(QStringList&)'
case 0: _t->options(reinterpret_cast< QStringList>(_v)); break;
^ -
I updated the code above to make it more efficient. how are you using it?
-
this->m_tableview_main->setItemDelegateForColumn(4, new ComboDelegate);
But I have the same problem as above.
The list of available items is black.What I have to do show editor permanently not only at edition mode?
-
@Kaluss said in Black list of QCombobox items:
What I have to do show editor permanently not only at edition mode?
reimplement paint() on the delegate.
Before I get into it. Are you 100% adamant you don't set a stylesheet anywhere in the tableView or the widgets that are in parental relationship to it?
-
Hi,
I found the reason. But it's not completely clear for me.
It was:
this->m_tableview_main->setStyleSheet("background-color:transparent;");Anyway, thanks for your help and examples.
It helped me much.BR/T