QDockWidgets的关闭状态没有被restoreDockWidget恢复?

发布于 2024-08-20 05:54:55 字数 530 浏览 2 评论 0原文

我试图在应用程序退出并重新启动时保存/恢复 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰魂雪魄 2024-08-27 05:54:55

检查 Qt 的代码(版本 4.5.0)发现以下内容:(

bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget)
{
   ...
   dockWidget->show();
   // dockWidget->setVisible(!placeHolder->hidden);
   ...
}

请注意,QDockAreaLayoutQMainWindow 使用的私有 Qt 类)。

我不确定为什么设置停靠小部件可见性的行被注释掉,并替换为每次显示停靠小部件的行。我在 Qt Bug Tracker 中也找不到这方面的 bug;对我来说这似乎是一个错误。

看起来您必须手动管理停靠小部件的可见性。

Examining Qt's code (version 4.5.0) revealed the following:

bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget)
{
   ...
   dockWidget->show();
   // dockWidget->setVisible(!placeHolder->hidden);
   ...
}

(Note that QDockAreaLayout is a private Qt class that is used by QMainWindow).

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文