QTreeView with fixed column widths

ⅰ亾dé卋堺 提交于 2019-12-04 19:48:18

The problem is that the resize mode is applied to all the sections uniformly. You can use the overload of QHeaderView::setSectionResizeMode that allows per-section settings to fine-grain tuning. In your case, using a combination of resize modes: QHeaderView::Stretch for expanding columns and QHeaderView::Fixed for those with fixed width.

Also, you have to disable the setting that automatically stretches the last section. Use QHeaderView::setStretchLastSection.

Example:

header->setSectionResizeMode(0, QHeaderView::Stretch);
header->setSectionResizeMode(1, QHeaderView::Fixed);
header->setSectionResizeMode(2, QHeaderView::Fixed);
header->setStretchLastSection(false);

Finally, the QItemDelegate::sizeHint doesn't have any effect over sections marked with a QHeaderView::Fixed resize mode. Just call the resizeSection with the desired width and forget about the item delegate (unless you need for anything else).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!