title: How to end an edit session with QPlainTextEdit editor?
body: <p>Here's an MRE:</p>
  <pre><code>from PyQt5.QtCore import QRect, Qt, QAbstractTableModel
  from PyQt5.QtWidgets import QApplication, QMainWindow, QTableView, QWidget, QVBoxLayout, QStyledItemDelegate, QPlainTextEdit, QShortcut
  import sys, types
  from PyQt5.QtGui import QFont
  
  class HistoryTableViewDelegate( QStyledItemDelegate ):
      def __init__( self, history_table_view ):
          super().__init__( history_table_view )
      
      def createEditor(self, parent, option, index):
          editor = QPlainTextEdit( parent )
          editor.setSizeAdjustPolicy( QPlainTextEdit.SizeAdjustPolicy.AdjustToContents )
          self.model = index.model()
          column = index.column()
          row = index.row()
          parent.parent().verticalHeader().resizeSection( row, 150 )
          parent_font = QFont( self.parent().font() )
          parent_font.setPointSize( self.parent().font().pointSize() )
          editor.setFont( parent_font )
          def end_edit():
              print( f'end edit...')
              self.setModelData( editor, self.model, index )
              # how to end the edit session programmatically at this point?
              # self.destroyEditor( editor, index ) 
              
          end_edit_shortcut = QShortcut(  'Alt+E', editor, context = Qt.ShortcutContext.WidgetShortcut )
          end_edit_shortcut.activated.connect( end_edit )
          return editor
      
      def setEditorData(self, editor, index ):
          # NB superclass method sets the editor's text to empty string...
          self.original_text = index.model().data( index, Qt.DisplayRole )
          editor.insertPlainText( str( self.original_text ) )     
          
  class HistoryTableModel( QAbstractTableModel ):
      def __init__( self ):
          super(HistoryTableModel, self).__init__()
          data = [
                [4, 9, 2],
                [1, 0, 0],
                [3, 5, 0],
          ]
          self._data = data
  
      def data(self, index, role):
          if role == Qt.DisplayRole:
              return self._data[index.row()][index.column()]
  
      def rowCount(self, index):
          return len(self._data)
  
      def columnCount(self, index):
          return len(self._data[0])
      
      def flags(self, index):
          return Qt.ItemIsEnabled | Qt.ItemIsSelectable | Qt.ItemIsEditable
      
      def setData(self, index, value, role ):
          if role == Qt.EditRole:
              self._data[ index.row() ][ index.column() ] = value  
          return True  
  
  class Ui_MainWindow(object):
      def setupUi(self, MainWindow):
          MainWindow.resize(600, 700 )
          self.centralwidget = QWidget(MainWindow)
          self.verticalLayoutWidget = QWidget(self.centralwidget)
          self.verticalLayoutWidget.setGeometry( QRect(20, 20, 500, 500))
          self.verticalLayout = QVBoxLayout(self.verticalLayoutWidget)
          self.comps = []
          self.table_view = QTableView(self.verticalLayoutWidget)
          self.comps.append( self.table_view )
          self.table_view.setGeometry(QRect(20, 20, 200, 200))
          self.verticalLayout.addWidget(self.table_view)
          self.table_view.setModel( HistoryTableModel() )
          self.table_view.setTabKeyNavigation(False)
          self.table_view.setItemDelegate( HistoryTableViewDelegate( self.table_view ))
          MainWindow.setCentralWidget(self.centralwidget)
  
  class MainWindow(QMainWindow):
      def __init__(self):
          super(MainWindow, self).__init__()
          self.ui = Ui_MainWindow()
          self.ui.setupUi(self)
  
  app = QApplication(sys.argv)
  application = MainWindow()
  application.show()
  sys.exit(app.exec())
  </code></pre>
  <p>I want to have a multi-line editor so I think I have understood the way to go is <code>QPlainTextEdit</code>. Although, with the above, pressing Alt-E commits the data to the model, it doesn't actually end the session. If, for example, you click with the mouse on another cell you can see that the edited multi-line data remains in the edited cell, and doing that somehow also ends the edit session.</p>
  <p>How can I end the session programmatically?</p>
  <p>NB pressing Escape after pressing Alt-E is a way to do this (in two keystrokes)... but I essentially want to do whatever programmatic thing pressing Enter does with a <code>QLineEdit</code> editor.</p>