Well I got it to work for one item, but for two or more items the second item fails. I think the call to edit gets on the event loop and so things are not whre they ought to be. Here is what I have
@// main loop where I want to set the data:
for (int i=i=0;i<childCount;i++) {
valueDestin = (FieldValueItem)destination.child(i,AvailableValueCol);
QModelIndex mi = valueDestin->index();
if ((i == 2) || (i == 3)) {
fieldValueDelegate->setSilent(true,1); // set index to item
availableFieldsTree->edit(mi);
// qApp->processEvents(QEventLoop::WaitForMoreEvents,500);
//availableFieldsTree->closePersistentEditor(mi);
//qApp->processEvents(QEventLoop::WaitForMoreEvents,500);
fieldValueDelegate->setSilent(false,-1);
}
....
void FieldValueDelegate::setSilent(bool on, int ci)
{
isSilent = on;
comboIndex = ci;
if (!isSilent)
editCB = 0;
}
void FieldValueDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const
{
qDebug() << "Set Editor Data" << FILE << LINE;
QComboBox *cb = qobject_cast <QComboBox *> (editor);
if (cb && isSilent) {
cb->setCurrentIndex(comboIndex);
}
QStyledItemDelegate::setEditorData(editor,index);
}
@
If I just have i set to 2, or i set to 3 (that is one index) in the loop above the index will get set, and I will see the result in my treeview, but when I try to both indexes in it fails on the second pass . There is an error message from Qt on the second iiteration:
editing failed
I guess Qt was not made to do this kind of stuff. If you know a quick fix please let me know, otherwise I will just give this thread a rest. Thanks to all that tried to help