我有一个QMainWindow,其中包含许多小部件(在容器内)。我需要将此容器及其布局和所有内部小部件/参数保存到文件中。然后我可以将此文件加载到新的QMainwindow中,是否可以在PyQt5中完成!!
下面是Window和包含小部件的容器的示例代码。目的是:
谢谢
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit, QWidget,QVBoxLayout
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtCore import QSize
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(600, 400))
self.setWindowTitle("Save Widget to be loaded again")
"QWidget"
self.container = QWidget(self)
self.container.move(20,20)
self.container.resize(400, 400)
"Layout"
self.layout = QVBoxLayout()
self.container.setLayout(self.layout)
"Widget #1"
self.line = QLineEdit()
self.line.resize(200, 32)
self.layout.addWidget(self.line)
"Widget #2"
self.button = QPushButton('OK')
self.button.resize(200,32)
self.layout.addWidget(self.button)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit( app.exec_() )