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 an开发者_JAVA技巧d committing the changes. How should I go about this?
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);
}
}
}
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 )
精彩评论