The QTableView uses QHeaderView instances to manage the horizontal and vertical column headers. You can use the QHeaderView::sectionResized() signal to get notification when a column in one table is resized. Connect this signal to a slot where you call the QHeaderView::resizeSection() method on the other table's header and vice versa.
I would put the code to do this in the widget that contains the two tables in the VBox. Be careful not to cause infinite recursion by calling the resizeSection() method on the same widget that issued the signal as well as not calling resizeSection() when the old and new sizes are the same. I do not know if the sectionResized() signal is sent only when the column is manually resized (ie, interactively with the mouse) or if it is also sent when the size is changed programmatically (through code). You'll have to test that, because that's where recursion could easily happen.
You should also check out this previous post on a similar problem.
You could have performance issues if your tables are large, because the table layout will be recalculated with every mouse move and call to resizeSection(). If this happens, you can decide to call resizeSection() only on every "nth" signal, when the size difference exceeds a certain amount, or only after a certain time has passed after the mouse has stopped moving (using a 250 ms QTimer, for example), or some combination of these to improve performance.
Bookmarks