PDA

View Full Version : Model/View: Custom Persistent Editor



No-Nonsense
6th February 2007, 17:02
I created a simple ItemDelegate that shows a custom editor on one of my TableView columns. Editing the items in this column works perfectly when using the standard mechanism (double-click on cell, make changes in editor, select another cell).

I made a change that the editor will be opened persistent on the current selected row:


void MainWindow::ruleTableViewSelectedRowChanged(const QModelIndex & current, const QModelIndex & previous)
{
// Update persistent InputColumn editor.
ruleTableView->closePersistentEditor(ruleTableView->model()->index(previous.row(), RuleTableModel::InputColumn));
ruleTableView->openPersistentEditor(ruleTableView->model()->index(current.row(), RuleTableModel::InputColumn));

Now changes to the editor will not be saved when changing the row unless I hit enter while having the editor selected.

I tried the behaviour of a standard ItemDelegate (SpinBox) and the changes to it will be saved, so I assume I need to change my custom ItemDelegate to commit changes directly when something is changed and not only when setModelData gets called?

Thanks in advance,
-Jens

wysota
6th February 2007, 17:12
Call QAbstractItemDelegate::commitData() on your editor before closing it.

No-Nonsense
7th February 2007, 15:55
Call QAbstractItemDelegate::commitData() on your editor before closing it.

How would I do this? QItemDelegate only has methods to create an editor but deletes it on its own.

I had a look at the Qt doc example http://doc.trolltech.com/4.2/itemviews-spinboxdelegate.html and they want me to install an event filter: "We install an event filter on the spin box to ensure that it behaves in a way that is consistent with other delegates. The implementation for the event filter is provided by the base class."

I then had a look at QItemDelegate but there they do not install an event filter in createEditor so why should I do (I tried and it did not help with my problem).

Why do the standard Qt ItemDelegates (QComboBox, QSpinBox, QLineEdit) work as expected? When do they call commitData?

Thanks in advance,
-Jens