QTableView 和 horizo​​ntalHeader()->restoreState() [英] QTableView and horizontalHeader()->restoreState()

查看:37
本文介绍了QTableView 和 horizo​​ntalHeader()->restoreState()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法缩小这个错误的范围,但是我似乎有以下问题:

I can't narrow down this bug, however I seem to have the following problem:

  • saveState() 一个 horizo​​ntalHeader()
  • 重启应用
  • 修改模型,使其少一列
  • restoreState()
  • 现在,由于某种原因,headerview 的状态完全混乱了.我无法显示或隐藏任何新列,也无法恢复合理的状态

我知道,这不是很具有描述性,但我希望其他人以前遇到过这个问题.

I know, this is not very descriptive but I'm hoping others have had this problem before.

推荐答案

对于 QMainWindow,save/restoreState 需要一个版本号.QTableView 的 restoreState() 没有,所以你需要管理这个case自己.

For QMainWindow, the save/restoreState takes a version number. QTableView's restoreState() does not, so you need to manage this case yourself.

如果您想在模型不匹配的情况下恢复状态,您有以下选择:

If you want to restore state even if the model doesn't match, you have these options:

  • 保存时将状态与模型中存在的列的列表一起存储,这样您就可以避免在列不匹配时从数据中恢复,并恢复到默认情况
  • 实现您自己的 save/restoreState 函数来处理这种情况(呃)
  • 添加一个代理模型,该模型为正在恢复的状态提供虚假/虚拟列,然后立即删除这些列.

这篇关于QTableView 和 horizo​​ntalHeader()->restoreState()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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