当前位置: 代码迷 >> QT开发 >> QTableView设置列宽没效果.解决方法
  详细解决方案

QTableView设置列宽没效果.解决方法

热度:105   发布时间:2016-04-25 03:19:42.0
QTableView设置列宽没效果...
一个sqlmodel
在view的构造函数里初始化 
我测试了一下每列的列宽 都是100
但是显示的时候 明显不一样  好像是我的数据有多长 列宽就有多长 但是我还没有调用那个自动适应数据的列宽函数
我的一个combox托管 在选择值的时候 已经窄的 把字符串显示成"..."了 但是另外一列的combox托管就比较宽 
我使用setColumnWidth 但是没有效果 
求各位指导一下
------解决方案--------------------
是不是用的SetMode这种的,列宽的代码应该在SetMode之后才起作用,我也出现过这种问题,不知道能不能解决你的问题。
------解决方案--------------------
enum QHeaderView::ResizeMode
The resize mode specifies the behavior of the header sections. It can be set on the entire header view or on individual sections using setSectionResizeMode().

Constant Value Description
QHeaderView::Interactive 0 The user can resize the section. The section can also be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize. (See also cascadingSectionResizes.)
QHeaderView::Fixed 2 The user cannot resize the section. The section can only be resized programmatically using resizeSection(). The section size defaults to defaultSectionSize.
QHeaderView::Stretch 1 QHeaderView will automatically resize the section to fill the available space. The size cannot be changed by the user or programmatically.
QHeaderView::ResizeToContents 3 QHeaderView will automatically resize the section to its optimal size based on the contents of the entire column or row. The size cannot be changed by the user or programmatically. (This value was introduced in 4.2)
  相关解决方案