tags:

views:

77

answers:

1

What im trying to do is have a table which does not appear editable directly but can be edited in some widget outside the table. That is, the selected node can be edited here, and all nodes use the same editor because i want it to always be shown.

What I've tried is to subclass QItemDelegate and just return the instance of QTextEdit i already have, like this:

class Delegate extends QItemDelegate {
    @Override
    public QWidget createEditor(QWidget parent, QStyleOptionViewItem option, QModelIndex index) {
        return qtextEdit; 
    }
}

which works, except that when you leave the editor it gets destroyed. Maybe delegate isn't supposed to be used this way. So how can i achieve this?

(ps. im using jambi but c++ code is fine)

+2  A: 

The QDataWidgetMapper class is exactly what you want, to edit the values of whatever record outside of the view in external controls.

Taken straight from the documentation, this is how you'd use it:

QDataWidgetMapper *mapper = new QDataWidgetMapper;
mapper->setModel(model);
mapper->addMapping(mySpinBox, 0);
mapper->addMapping(myLineEdit, 1);
mapper->addMapping(myCountryChooser, 2);
mapper->toFirst();

And, if you have a view (QTreeView / QListView / QTableView / etc) and you want to edit the currently selected item, connect the appropriate signal & slot: connect(&view, SIGNAL(activated(QModelIndex)), mapper, SLOT(setCurrentModelIndex(QModelIndex)));

ianmac45
Yeah that *is* exactly what i wanted. thanks!:)
takoi