Qt - Pyside - .saveGeom() .saveState()(再次) [英] Qt - Pyside - .saveGeom() .saveState() (again)

查看:51
本文介绍了Qt - Pyside - .saveGeom() .saveState()(再次)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对Qt - pyside - saveGeometry() saveState() 的后续问题

我有一个 Qt 程序,目前我使用 Qsettings 和 mainWindow.saveGeometry() 和 mainWindow.saveState() 函数来允许程序恢复用户在上一个会话中设置的布局.

I have a Qt program and currently I use Qsettings and the mainWindow.saveGeometry() and mainWindow.saveState() functions to allow the program to restore the layout that the user set in the previous session.

这种方法适用于所有停靠窗口的停靠位置.如果窗口在退出时未停靠,它也适用于未停靠窗口的浮动位置.

This approach works well for the docked position of all the docked windows. It also works well for the floating position of the un-docked windows provided the windows are un-docked at exit.

当用户在会话中根据自己的需要定制浮动窗口的位置时,停靠并重新浮动窗口会使其成功恢复用户的首选位置.

When a user tailors the position of the floating window to their needs within a session, docking and re-floating the window cause it to successfully restore the users preferred position.

但是当用户定制了窗口的大小和位置,然后停靠窗口然后退出时,就会出现问题.重新启动时,窗口不会恢复用户首选的浮动位置.

However the problem arises when the user has tailored the size and position of the window and then docks the window and then exits. On restart the window does not recover the users preferred floating position.

上面链接的另一个问题的答案中的所有建议都没有帮助,因为 QdockWidget 没有任何 getGeom() setGeom() 类型的方法.它也没有自己的 seveGeometry() restoreGeometry() 方法.我想主窗口方法也应该处理停靠小部件.但上述行为达不到所需的功能.

None of the suggestions in the answers to the other question linked above are helpful since QdockWidget does not have any getGeom() setGeom() type methods. Neither does it have its own seveGeometry() restoreGeometry() methods. I guess the main window methods are supposed to take care of dockedwidgets too. But the above behaviour falls short of the desired functionality.

我曾尝试在 QdockWidget 的 widget() 方法返回的对象上使用 save 和 restore 方法,但那不起作用.(它修改的是QdockWidget的内容,而不是浮动窗口的位置)

I have tried using save and restore methods on the object returned by the widget() method of QdockWidget but that does not work. (It modifies the contents of the QdockWidget and not the position of the floating window)

所以我认为我提炼的问题是:
1) 是否有其他人在主窗口保存/恢复时观察到上述缺点,或者我是否正在做一些事情来阻止停靠窗口的正确恢复.
2) QdockWidget有什么方法可以获取和设置浮动几何体吗?

So I think my refined questions are these:
1) Have others observed the above shortcoming with main window save/restore or might I be doing something to block proper restoring of the docked windows.
2) Is there any way to get and set the floating geometry of the QdockWidget?

推荐答案

好的.这是答案.Qt 中有一个错误.当主窗口最大化并且 QdocWidget 停靠(不浮动)时,则不保存浮动位置.

Ok guys. Here is the answer. There is a bug in Qt. When the main window is maximised and the QdocWidget's are docked (not floating) then the floating position is not saved.

此代码是一个简单的解决方法.

This code is a simple workaround.

保存:

settings = QtCore.QSettings(org_name, app_name)
is_floating = main_win._ui.dockWin.isFloating()
settings.setValue('dockWin/isFloating', is_floating)
main_win._ui.dockWin.setFloating(True)
settings.setValue('geometry', main_win.saveGeometry())
settings.setValue('state', main_win.saveState())

恢复:

settings = QtCore.QSettings(org_name, app_name)
main_win.restoreGeometry(settings.value('geometry'))
main_win.restoreState(settings.value('state'))
main_win._ui.dockWin.setFloating(settings.value('dockWin/isFloating')=='true')

这篇关于Qt - Pyside - .saveGeom() .saveState()(再次)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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