SHARE
TWEET

Untitled

a guest Oct 15th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PySide2 import (QtCore, QtGui, QtWidgets)
  2. from table_model import CustomTableModel
  3.  
  4. class TextBoxDelegate(QtWidgets.QItemDelegate):
  5.  
  6.     def __init__(self):
  7.         QtWidgets.QItemDelegate.__init__(self)
  8.         # some code skipped
  9.    
  10. class EditorView(QtWidgets.QTableView):
  11.     ''' Subclassing QTableview for reimplementing keyPressEvent '''
  12.  
  13.     def keyPressEvent(self, event):
  14.        
  15.         print(event.key())
  16.         # (!!!) QtCore.Qt.Key_Down event ignored here (!!!)
  17.  
  18.     def __init__(self, source_data = None, translated_data = None):
  19.         QtWidgets.QTableView.__init__(self)
  20.        
  21.         # CustomTableModel
  22.         self.model = CustomTableModel(source_data, translated_data)
  23.         self.setModel(self.model)
  24.         self.setEditTriggers(QtWidgets.QAbstractItemView.AllEditTriggers)
  25.    
  26.  
  27.    
  28. class Widget(QtWidgets.QWidget):
  29.  
  30.     def __init__(self, source_data = None, translated_data = None):
  31.         QtWidgets.QWidget.__init__(self)
  32.  
  33.         self.tableView = EditorView(source_data, translated_data)
  34.         delegate = TextBoxDelegate()
  35.         self.tableView.setItemDelegate(delegate)
  36.  
  37.         # Another code ignored here
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top