Exemplo n.º 1
0
    def closeEditor(self, editor, hint):
        # The problem we're trying to solve here is the edit-and-go-away problem.
        # When ending the editing with submit or return, there's no problem, the
        # model's submit()/revert() is correctly called. However, when ending
        # editing by clicking away, submit() is never called. Fortunately,
        # closeEditor is called and, AFAIK, it's the only case where it's called
        # with NoHint (0). So, in these cases, we want to call model.submit()
        if hint == QAbstractItemDelegate.NoHint:
            QTableView.closeEditor(self, editor,
                                   QAbstractItemDelegate.SubmitModelCache)

        # And here, what we're trying to solve is the problem with editing
        # next/previous lines. If there are no more editable indexes, stop
        # editing right there. Additionally, we are making tabbing step over
        # non-editable cells
        elif hint in (QAbstractItemDelegate.EditNextItem,
                      QAbstractItemDelegate.EditPreviousItem):
            if hint == QAbstractItemDelegate.EditNextItem:
                editableIndex = self._nextEditableIndex(self.currentIndex())
            else:
                editableIndex = self._previousEditableIndex(
                    self.currentIndex())
            if editableIndex is None:
                QTableView.closeEditor(self, editor,
                                       QAbstractItemDelegate.SubmitModelCache)
            else:
                QTableView.closeEditor(self, editor, 0)
                self.setCurrentIndex(editableIndex)
                self.edit(editableIndex)
        else:
            QTableView.closeEditor(self, editor, hint)
Exemplo n.º 2
0
    def closeEditor(self, editor, hint, close=False):
        """
        """
        if 'EF' in self.state_ and close == False:
            editor.clearFocus()
            self.setFocus()
            return
        #if editor.text() != '' and editor.text().strip()[0] == '=' and close==False:
        #    editor.clearFocus()
        #    self.setFocus()
        #    return
        val = QTableView.closeEditor(self, editor, hint)
        self.state_ = 'N'

        return val