Send click events to treewidgetitem

This commit is contained in:
Luke Campagnola 2017-07-31 10:03:13 -07:00
parent f5775422c6
commit ea51a65dfd

View File

@ -23,6 +23,7 @@ class TreeWidget(QtGui.QTreeWidget):
self.setEditTriggers(QtGui.QAbstractItemView.EditKeyPressed|QtGui.QAbstractItemView.SelectedClicked)
self.placeholders = []
self.childNestingLimit = None
self.itemClicked.connect(self._itemClicked)
def setItemWidget(self, item, col, wid):
"""
@ -230,6 +231,10 @@ class TreeWidget(QtGui.QTreeWidget):
QtGui.QTreeWidget.setColumnCount(self, c)
self.sigColumnCountChanged.emit(self, c)
def _itemClicked(self, item, col):
if hasattr(item, 'itemClicked'):
item.itemClicked(col)
class TreeWidgetItem(QtGui.QTreeWidgetItem):
"""
@ -338,6 +343,12 @@ class TreeWidgetItem(QtGui.QTreeWidgetItem):
elif (role in (QtCore.Qt.DisplayRole, QtCore.Qt.EditRole) and text != self.text(column)):
treewidget.sigItemTextChanged.emit(self, column)
def itemClicked(self, col):
"""Called when this item is clicked on.
Override this method to react to user clicks.
"""
class InvisibleRootItem(QtGui.QTreeWidgetItem):
"""Wrapper around a TreeWidget's invisible root item that calls