Originally Posted by
aekilic
Like the combos should be in the 2nd coloum.
You can create combo box editors to 2nd column like this:
{
if (index.column() == 1)
{
// 2nd column is being edited, return a QComboBox as an editor
...
return editor;
}
}
QWidget *ComboBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
if (index.column() == 1)
{
// 2nd column is being edited, return a QComboBox as an editor
QComboBox *editor = new QComboBox(parent);
...
return editor;
}
return QItemDelegate::createEditor(parent, option, index);
}
To copy to clipboard, switch view to plain text mode
Originally Posted by
aekilic
For the spin box delegate doesnt help, because the data in the combo changes allways
Sure it does. setEditorData() gets always called for the item in question. Just fill the combo box accordingly:
void ComboBoxDelegate
::setEditorData(QWidget *editor,
{
if (index.column() == 1)
{
// 2nd column is being edited, we know it's a QComboBox
// fill the combo box with anything you want
QComboBox *comboBox
= static_cast<QComboBox
*>
(editor
);
comboBox->addItem(...);
...
}
else
{
}
}
void ComboBoxDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
if (index.column() == 1)
{
// 2nd column is being edited, we know it's a QComboBox
// fill the combo box with anything you want
QComboBox *comboBox = static_cast<QComboBox*>(editor);
comboBox->addItem(...);
...
}
else
{
QItemDelegate::setEditorData(editor, index);
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks