Dirk
Dirk

Reputation: 1234

Closing editors of QAbstractItemView

I'm using a QAbstractItemView to manipulate a queue. The problem is that the editor doesn't close and update the value in the model when the user hits the send button. This causes some frustration.

I've gone through the Qt docs, but I can't seem to find a simple way of closing the editor and committing the changes. How should I go about this?

Upvotes: 1

Views: 2196

Answers (2)

gremwell
gremwell

Reputation: 1457

This is what I used

void ProjectExplorerView::CloseCurrentEditorIfOpen(bool commit)
{
   QWidget* w = indexWidget(currentIndex());
   if (w != nullptr)
   {
     if (commit) {
        commitData(w);
        closeEditor(w, QAbstractItemDelegate::SubmitModelCache);
     } else {
        closeEditor(w, QAbstractItemDelegate::RevertModelCache);
     }
   }
 }

Upvotes: 2

Harald Scheirich
Harald Scheirich

Reputation: 9764

Looks like you would have to track the currently open item through the selection model or the ItemView signals or currentIndex(), when you have QModelIndex of the item that is currently open you should be able to close it using closePersistentEditor ( const QModelIndex & index )

Upvotes: 0

Related Questions