QTableView列宽 [英] QTableView column width

查看:146
本文介绍了QTableView列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力在 QTableView 中手动设置列宽。
为什么这段代码不起作用?

I'm struggling to set column width manually in a QTableView. Why doesn't this piece of code work?

tabb = new QTableView;
tabb->resizeColumnsToContents();

for (int col=0; col<20; col++) 
{
   tabb->setColumnWidth(col,80);
}

如果我省略 tabb-> resizeColumnsToContents() ; 仍然无效。

推荐答案

您应该先设置模型,然后再设置模型能够更改 ColumnWidth

You should set model first and after this you will be able to change ColumnWidth:

tabb = new QTableView;
tabb->setModel(someModel);

for (int col=0; col<20; col++) 
{
   tabb->setColumnWidth(col,80);
}

这篇关于QTableView列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆