I have an application which uses a QTreeWidget and QTreeWidgetItems. If a new item gets added to the treeWidget (right click -> add item) it is possible to write in column "Header 1". If the tab key is pressed the focus jumps to the column "Header 0" which can be written as well. The desired behaviour is that by pressing the tab key the QTreeWidgetItem becomes non-editable. I have alreay tried to solve it by catching the tab key event within a modified QTreeWidgetItem class. Unfortunately the tab key event does not get catched. Example: from PyQt5 import QtCore, QtGui, QtWidgets class CTreeWidgetItem(QtWidgets.QTreeWidgetItem): def __init__(self, parent=None): QtWidgets.QTreeWidgetItem.__init__(self, parent) def keyPressEvent(self, event): if event.key()==QtCore.Qt.Key_Tab: self.setFlags(self.flags()|~QtCore.Qt.ItemIsEditable) print('not working') def create_treeWidget(): treeWidget=QtWidgets.QTreeWidget() treeWidget.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) treeWidget.customContextMenuRequested.connect(openContextMenu) treeWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) treeWidget.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection) treeWidget.setTabKeyNavigation(True) treeWidget.headerItem().setText(0, "Header 0") treeWidget.headerItem().setText(1, "Header 1") treeWidget.headerItem().setText(2, "Header 2") return treeWidget def openContextMenu(event): menu=QtWidgets.QMenu() action=menu.addAction('add item', addItem) menu.exec_(tree.mapToGlobal(event)) def addItem(): item=CTreeWidgetItem(tree) item.setFlags(item.flags()|QtCore.Qt.ItemIsEditable) tree.editItem(item, 1) if __name__ == "__main__": import sys app=QtWidgets.QApplication(sys.argv) app.setStyle("fusion") tree=create_treeWidget() tree.show() sys.exit(app.exec_()) Furthermore I do not understand the behaviour of the tab key inside a QTreeWidget. Case 1: New items are added by right click. Using tab key it is possible to jump between the different headers within the same item. Case 2: If an old item gets double clicked and a column gets edited, tab key just causes jumping between the items and the focused column stays the same. Maybe someone can explain why (I do not know how to call it) the focus of the tab key is changed. Thank you guys Continue reading...