Your question is a little ambiguous. What does 'catch the return key' mean? QTableWidget
has several methods that return information.
If you wanted to get the current cell's text you could simply do:
my_table.currentItem().text()
UPDATE
In your comment below, you specified that you want the user to be able to press Enter
or Return
and then be able to process the current items information.
To do this you create a subclass of QTableWidget
and override its keyPressEvent
method. Some of the inspiration came from here:
class MyTableWidget(QTableWidget):
def __init__(self, parent=None):
super(MyTableWidget, self).__init__(parent)
def keyPressEvent(self, event):
key = event.key()
if key == Qt.Key_Return or key == Qt.Key_Enter:
# Process current item here
else:
super(MyTableWidget, self).keyPressEvent(event)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…