gpt4 book ai didi

python - 如何记住 PyQt 应用程序的最后一个几何图形?

转载 作者:太空狗 更新时间:2023-10-29 23:39:32 24 4
gpt4 key购买 nike

我在 Windows 8.1 上使用 PyQt5 5.5.1(64 位)和 Python 3.4.0(64 位)64 位。

我无法恢复我的位置和大小(几何)非常简单的 PyQt 应用程序。

这是最小的工作应用程序:

import sys
from PyQt5.QtWidgets import QApplication, QWidget

class myApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()


def initUI(self):
self.show()

if __name__ == '__main__':
app = QApplication(sys.argv)
view = myApp()
sys.exit(app.exec())

我在网上看到的是这是默认行为,我们需要使用 QSettings 从 Windows 注册表保存和检索设置,存储在

\\HKEY_CURRENT_USER\Software\{CompanyName}\{AppName}\

Here are some of the links I read .

我本可以遵循那些教程,但那些教程/文档是为 C++ 用户编写。

C++ 不是我的菜,转换这些代码对我来说是不可能的。


相关:

QSettings(): How to save to current working directory

最佳答案

这应该可以。

import sys
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import QSettings, QPoint, QSize

class myApp(QWidget):
def __init__(self):
super(myApp, self).__init__()

self.settings = QSettings( 'My company', 'myApp')

# Initial window size/pos last saved. Use default values for first time
self.resize(self.settings.value("size", QSize(270, 225)))
self.move(self.settings.value("pos", QPoint(50, 50)))

def closeEvent(self, e):
# Write window size and position to config file
self.settings.setValue("size", self.size())
self.settings.setValue("pos", self.pos())

e.accept()

if __name__ == '__main__':
app = QApplication(sys.argv)
frame = myApp()
frame.show()
app.exec_()

我简化了这个例子:QSettings(): How to save to current working directory

关于python - 如何记住 PyQt 应用程序的最后一个几何图形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33869721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com