Columns auto-resize to size of QTableView

khajvah picture khajvah · Aug 17, 2013 · Viewed 60.6k times · Source

I am new to Qt and I have just managed to make a QTableView work with my model. It has fixed 3 columns. When I open a window, it look ok but when i resize the window, the QTableView itself gets resized but columns' width remains the same. Is there any build-in way to make it work? I want columns to resize to fit the edges of QTableView every the the window gets resized.

Answer

frogatto picture frogatto · Dec 9, 2015

This code equally stretchs each columns so that they fit the table's width.

table->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);

Docs: