Sometimes we may use openPersistentEditor() and closePersistentEditor() to keep editor of delegate opened.
For example, when entered() signal is generated, we close old persistent editor and open new persistent editor to make real editor widget always locates on the cell that mouse is pointing on.
However, the QModelIndex instance from entered() signal will be destroyed after the slot connected to entered() is returned. If we call openPersistentEditor() with the QModelIndex instance from entered() signal, I found that call closePersistentEditor() with QModelIndex:
1. has same instance as what we used to call openPersistentEditor()
2. has another instance that contains same row, column, and parent as what we used to call openPersistentEditor()
will failed, both of them.
If we want to open persistent editor and close it later in slots that entered() signal is connecting, we should create new index with model.index(index.row(), index.column()).
(Caution: directly assign index.parent() to the 3rd argument of model.index() causes the same problem, parent index should be cloned, too.)
沒有留言:
張貼留言