有两个函数返回列宽,
函数A:virtual protected int QTreeView::sizeHintForColumn(int column) const
函数B:int QTreeView::columnWidth(int column) const
它们返回的宽度有所不同,例如当进行如下设置后:
header()->setStretchLastSection(false);
treeView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
A、B函数返回的列宽如图:
而当进行如下设置后:
header()->setStretchLastSection(false);
treeView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
A、B函数返回的列宽如图: