QTreeView* treeView = new QTreeView(this); QHeaderView* header = treeView->header(); header->setStretchLastSection(true);
QTableWidget* tableWidget = new QTableWidget(this); QHeaderView* header = tableWidget->horizontalHeader(); header->setStretchLastSection(true);This sets the last visible section of the horizontal header in the QTableWidget widget to take up all available space. These examples are using the Qt library in C++.