QT QTableView sets column width adaptive and horizontal scrolling

Just two lines of code

    //设置tableView水平滚动和自适应宽度
	ui.tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
	ui.tableView->horizontalHeader()->setStretchLastSection(false);

Similarly, similar controls can also use the same method. For example:
QTreeWidget

	//设置TreeWidget水平滚动和自适应宽度
	ui.treeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
	ui.treeWidget->header()->setStretchLastSection(false);

————————————————
Copyright statement: This article is an original article of CSDN blogger "WJsuperrunner", following the CC 4.0 BY-SA copyright agreement, please attach the original source link and this statement for reprinting .
Original link: https://blog.csdn.net/superrunner_wujin/article/details/104513810/

Guess you like

Origin blog.csdn.net/wuquan_1230/article/details/125235299