the part from [ = ] onward is a slot. you just have to declare a private slot in your class with that body (the translation to python should be straightforward. you can remove the QVector argument and the first if as it's just optimisation) and connect the dataChanged signal of tableWidget.model() to it

and is it possible to implement the same functionality using Qt style sheet?