OK so the answer was partially thanks to @musicamante and partially thanks to AI, so I wrote in my table class init this code
self.header.sectionResized.connect(self.auto_n_manual_resize)
then wrote the class attribute _recursionCheck = False
and then modifies the resize method to this
def auto_n_manual_resize(self):
if self._recursionCheck:
return
self._recursionCheck = True
self.header.setStretchLastSection(False)
widget_width = self.wordsTable.contentsRect().width()
column0 = self.header.sectionSize(0)
column1 = self.header.sectionSize(1)
scroll = self.wordsTable.verticalScrollBar().sizeHint().width()
verHeadWidth = self.wordsTable.verticalHeader().sizeHint().width()
available_width = (
widget_width - verHeadWidth - scroll - 90
) # the 3rd col should be 90 pix wide
denom = column0 + column1 or 1
if denom == 0:
column0 = column1 = 1
denom = 2
col0_W_per = column0 / denom
col1_W_per = column1 / denom
newCol0Width = int(col0_W_per * available_width)
newcol1Width = int(col1_W_per * available_width)
self.wordsTable.setColumnWidth(0, newCol0Width)
self.wordsTable.setColumnWidth(1, newcol1Width)
self.wordsTable.setColumnWidth(2, 90)
self.header.setMinimumSectionSize(60)
self.header.setMaximumSectionSize((available_width))
self.header.setStretchLastSection(True)
self._recursionCheck = False
so now with the recursion check from @musicamante to prevent any recursion loop errors and moving the resize connection to init that gets called only once per resize without any connection/disconnection the program runs without any warning or error