QTableView根据内容自动调整大小(resizeColumnToContents解决不了的)
来源:互联网 发布:怎么删除多重网络 编辑:程序博客网 时间:2024/05/22 16:07
前言
最终解决方法(通过设置表头属性解决)
tableView = createView(mySqlQueryModel, QObject::tr("可颂坊报表系统")); //tableView->resizeColumnsToContents(); tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed); tableView->horizontalHeader()->setMinimumSectionSize(100); //tableView->horizontalHeader()->setSectionsMovable(true);本着爱折腾的精神,楼主又进一步思考了一些问题:是resizexxxxToContents()系列接口和表头的setSectionResizeMode()接口的同事作用还是只有表头的setSectionResizeMode()接口就可以解决显示不全问题?最后发现1.单独调用resizexxxxToContents()系列接口解决不了;2.同时调用resizexxxxToContents()系列接口和表头的setSectionResizeMode()接口解决了显示不全问题;3.单独调用表头的setSectionResizeMode()接口就可以解决显示不全问题。最终,楼主发现起作用的是表头的setSectionResizeMode()接口!所以当使用QTableView的resizexxxxToContents()系列接口可以解决显示不全的问题的时候就单独使用这系列的接口,行不通的话就使用表头的setSectionResizeMode()接口!
附录:表头(QHeaderView)的setSectionResizeMode()接口枚举参数
enum ResizeMode { Interactive, Stretch, Fixed, ResizeToContents, Custom = Fixed };
枚举常量
值
中文描述
英文描述
QHeaderView::Interactive
0
The user can resize the section. The section can also be resized programmatically usingresizeSection(). The section size defaults todefaultSectionSize. (See alsocascadingSectionResizes.)
用户可以重新调整表头的大小,也可以使用resizeSection()重新调整表头的大小。
QHeaderView::Fixed
2
The user cannot resize the section. The section can only be resized programmatically usingresizeSection(). The section size defaults todefaultSectionSize.
用户不可以重新调整表头的大小,只可以使用resizeSection()重新调整表头的大小。
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)
表头将自动根据整个行或者列的内容去调整表头单元格到最佳的大小。用户或者程序员通过代码都不能改变它的大小。
- QTableView根据内容自动调整大小(resizeColumnToContents解决不了的)
- QTableView根据内容自动调整列宽行高
- QTableView根据内容自动调整列宽行高
- QTableView根据内容自动调整列宽行高
- QTableView根据内容自动调整列宽行高
- 根据内容自动调整弹出窗口大小的JS解决方案
- 根据内容自动调整弹出窗口大小的JS解决方案
- 根据内容自动调整弹出窗口大小的JS解决方案
- 根据内容自动调整弹出窗口大小的JS解决方案
- 根据内容自动调整弹出窗口大小的JS解决方案
- 根据内容自动调整弹出窗口大小的JS解决方案
- 弹出窗口根据内容自动调整大小的JS解决方案
- Excel根据批注的内容自动调整批注大小
- showModalDialog根据内容自动调整窗口大小
- 使IFrame根据内容自动调整大小
- showModalDialog根据内容自动调整窗口大小
- iframe自动根据内容调整大小
- QTableView中文本根据内容自动换行的简单方法
- 基于SpringBoot的Jpa查询
- 进程控制
- Shop项目--4. 分页显示商品的,与分页跳转,上一页,下一页product_list.jsp
- 思岚科技邀你2017日本东京国际机器人展
- python中GIL问题(多线程问题,调用的函数用C语言写)
- QTableView根据内容自动调整大小(resizeColumnToContents解决不了的)
- Mysql_full_backup.sh
- iOS内存泄露,你做好iOS加密工作了吗?
- 进度条(一)
- iOS开发之基础篇(15)—— KVC、KVO
- 小白Java笔记——垃圾回收机制
- marquee功能:marquee的速度怎么设置
- HTML5的manifest缓存
- Git使用——与github共舞01