开发者

Closing editors of QAbstractItemView

开发者 https://www.devze.com 2023-01-28 13:02 出处:网络
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'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 )

0

精彩评论

暂无评论...
验证码 换一张
取 消