Black list of QCombobox items
-
Hi All,
I have following problem:
I'm adding into QTableView by setIndexWidget combobox for selected index.My problem is that when I click on combobox I see black list.
Names are only show when I put my mouse pointer on particular item.Does sombody know how can I handle that?
BR/T
-
Did you set a stylesheet?
The correct way, anyway is not to use setIndexWidget but reimplement QItemEditorFactory to make it create a combobox then set it to that column:
auto comboDelegate = new QStyledItemDelegate(tableView); comboDelegate->setItemEditorFactory(new MyComboFactory(comboDelegate)); tableView->setItemDelegateForColumn(/*index of column copy*/,comboDelegate);
-
@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;
^ -
@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?