// Set the horizontal header of a QTableView to resize contents tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); // Set the vertical header of a QTreeView to stretch treeView->verticalHeader()->setResizeMode(QHeaderView::Stretch);In the example above, we're using the setResizeMode() function to adjust the resizing mode of a horizontal header in a QTableView and a vertical header in a QTreeView. The first example sets the resize mode to ResizeToContents, meaning that the columns in the header will automatically size themselves to fit the content of the cells. The second example sets the resize mode to Stretch, meaning that the rows in the header will expand or shrink to fill available space. These code examples use the Qt library, specifically the QHeaderView class.