i have a qtablewidget which is updated asynchronosly.
now i am trying to set new values into the cells and read them back after hitting “enter/return”. i have a function that catches the keypressevent and try to read the actual value from the cell that was changed.
the problem: i only get the previous value of the cell, not the new entered value, because the function is called when the enter key is pressed which is right before the cell is updated whith the new value. i cannot use itemChanged().connect
because the table is also changed from another proccess and i only want to catch my own changes.
old value (before editing value)
editing the value and hit enter
function that is called after hitting return:
def tableOnKeyPressEvent(self, event): if event.key() == Qt.Key.Key_Return or event.key() == Qt.Key.Key_Enter: for a in self.CmdtableWidget.selectedItems(): print(a.text()) # prints only 789, not 123 QTableWidget.keyPressEvent(self.CmdtableWidget, event) # pass on the keyPressEvent to the table
Advertisement
Answer
i have a solution/ workaround for that problem: i had to change the current selected item. so the new value was applied and i could it read in the following.
after that:
self.CmdtableWidget.setCurrentItem(None) # leave cell,otherwise we get no updated value to read
the value was applied to the cell