调整 QTableView 中的列宽

7
在我的TableModel中,我有两列。这个模型连接到TableView。如何设置它们,使得这两列填充tableView,以便没有空余空间?
编辑:
enter image description here

自动调整列宽以适应父容器 - frogatto
1个回答

9

试试这个:

tableView->horizontalHeader()->setStretchLastSection(true);
tableView->resizeColumnsToContents(); // not necessarily but can make look better

不要在我的tableView界面中看到setStretchLastSection的设置。 - user336635
你怎么声明你的表视图? - Andrey Atapin
我已经从qt的Item Views部分/基于我的对话框的模型中拖动了它。 - user336635
tableView->horizontalHeader()->setStretchLastSection(true);感谢。 - user336635
我的错,我漏掉了水平标题。现在已经更新了答案。 - Andrey Atapin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接