QT笔记- QTreeView获取列宽

有两个函数返回列宽,

函数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函数返回的列宽如图:

 


版权声明:本文为qq_43058397原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。