How to resize QTableWidget columns
c++, qt, qtablewidget
Solution
- Change the `ResizeMode` of the `QHeaderView`. For example, use:
horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch );
to make the first column resize so the `QTableWidget` is always full.
- Override the `resizeEvent` and set the widths of each column yourself when the `QTableWidget` has been resized.
Problem
I have a MainWindow with a QToolbar, QWidget and a QTabWidget. The layout is "Grid". However, my window is resizeable and since I have a layout it works well. But there is one problem, in my QTabWidget I have a QTableWidget with two columns (layout is also "Grid"). If I resize my whole window, the QTableWidget resizes but not the columns. For example, whenever I resize my window, my QTabWidget resizes and the QTableWidget in it too. Only the columns in my QTableWidget won't. How can I resize them if my QTableWidget resizes?