如何让 QTableView 填充 100% 的宽度? [英] How to get a QTableView to fill 100% of the width?
本文介绍了如何让 QTableView 填充 100% 的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的软件的打印屏幕:
Here's a print screen of my software:
如您所见,第一个 QTableVIew
标题不占用 100% 的宽度.实际上,size
字段右侧有一个小的垂直空白.
As you can see, the first QTableVIew
headers do not take 100% of the width. In fact, there is a small vertical white space on the right of the field size
.
如何让标题占据 QTableView
宽度的 100%?
How can I get the headers to take 100% of the width of the QTableView
?
推荐答案
如果您使用的是 Qt 5,QHeaderView::setResizeMode()
不再可用.相反,您可以使用 QHeaderView::setSectionResizeMode()
:
If you are using Qt 5, QHeaderView::setResizeMode()
is no longer available. Instead, you can use QHeaderView::setSectionResizeMode()
:
ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
或者只是为每一列调用它:
Or just call it for every column:
for (int c = 0; c < ui->tableView->horizontalHeader()->count(); ++c)
{
ui->tableView->horizontalHeader()->setSectionResizeMode(
c, QHeaderView::Stretch);
}
这篇关于如何让 QTableView 填充 100% 的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文