I have a QTableWidget
populated with several QTableWidgetItem
objects. I am trying to add a mousePressEvent
listener to my QTableWidget
objects.
My current code is simple:
class TaskCell(QTableWidgetItem):
def __init__(self, text, parent):
super().__init__(text)
self.parent = parent
def mousePressEvent(self, event):
print("Mouse clicked on cell with parent" + self.parent.id)
This to me seems rather straight-forward but unfortunately is not working. Can I not add a mousePressEvent
to QTableWidgetItem
objects? Thank you kindly.
QTableWidgetItem is not a visual element but an information container so it does not have a method similar to mousePressEvent. What to do is override the mousePressEvent method of the QTableWidget and get the TaskCells: