I currently work on a pyside2 project. I use some QTableWidget and i was wondering if it is possible to, when i edit a QTableWidgetItem, the value during the edit is a part of a calcul and when i stop the editing, then it calcul the new value to display.
i already created an object "MyQTableWidgetItem" inherited from QTableWidgetItem. and "MyQTableWidgetItem" accepts an object as init.
and i imagined something like :
class MyObject:
def __init__(self, int_1, int_2):
self.int_1 = int_1
self.int_2 = int_2
def get_total(self):
return self.int_1 + self.int_2
class MyQTableWidgetItem(QTableWidgetItem):
def __init__(self, my_object: MyObject):
self.my_object = my_object
super(MyQTableWidgetItem, self).__init__(my_object.get_total())
def on_edit(self):
# modify only my_object.int_1 and not the entire calcul
# (show only my_object.int_1 for editing)
def on_stop_editing(self): #if needed
# will display my_object.get_total()
But i really have no idea how to do it, could you please tell me how to do it?
I can easily understand qt's c++ to translante it on pyside2 so, if you have some ideas with c++ i'll take it too.