So how to force the MainWindow to resize to the width of the table showing all columns ?
You don't, at least not in programs that behave in the way most people expect.

If you really must do it then you probably need to start with QHeaderView::length() and force the minimum width of the QTableView. Don't forget to handle the case of the able content being wider than the screen.