QDockWidgets的关闭状态没有被restoreDockWidget恢复?
我试图在应用程序退出并重新启动时保存/恢复 QDockWidgets 的位置和状态。我的主窗口中的流程如下:
restoreState(state.toByteArray());
// Dock widget gets created
restoreDockWidget(dockWidget);
这非常有效,除了一件事:如果应用程序退出时关闭停靠小部件,它们会在下次运行应用程序时重新出现到最后的位置,而我希望它们有初始隐藏状态。关于restoreDockWidget的使用,我有什么遗漏的吗?或者我应该手动处理停靠小部件的可见状态?
更新:请注意,如果我执行以下操作:
// Dock widget gets created
restoreState(state.toByteArray());
则先前隐藏的小部件将保持隐藏状态。不幸的是,我不能依赖这个方案,因为我有在主窗口恢复后由插件创建的停靠小部件。
编辑:似乎在最新的 Qt 版本中已修复。
I'm trying to get the positions and state of QDockWidgets saved/restored when the application is exited and relaunched. The flow in my main window is as follows:
restoreState(state.toByteArray());
// Dock widget gets created
restoreDockWidget(dockWidget);
This works great excepted for one thing: if dock widgets are closed when the application exits, they reappear into their last position the next time the application is run, while I'd expect them to have an initial hidden state. Is there something I missed about the usage of restoreDockWidget? Or should I handle the visible state of the dock widgets manually?
Update: Note that if I do as follows:
// Dock widget gets created
restoreState(state.toByteArray());
Then previously hidden widgets remain hidden. Unfortunately I cannot rely on this scheme as I have dock widgets that are created by plugins after the main window is restored.
Edit: seems to be fixed in latest Qt versions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查 Qt 的代码(版本 4.5.0)发现以下内容:(
请注意,
QDockAreaLayout
是QMainWindow
使用的私有 Qt 类)。我不确定为什么设置停靠小部件可见性的行被注释掉,并替换为每次显示停靠小部件的行。我在 Qt Bug Tracker 中也找不到这方面的 bug;对我来说这似乎是一个错误。
看起来您必须手动管理停靠小部件的可见性。
Examining Qt's code (version 4.5.0) revealed the following:
(Note that
QDockAreaLayout
is a private Qt class that is used byQMainWindow
).I'm not sure why the line to set the dock widget's visibility is commented-out and replaced with a line to show the dock widget every time. I also couldn't find a bug in the Qt Bug Tracker for this; it seems like a bug to me.
It looks like you'll have to manage the visibility of the dock widgets manually.