[英]How to save/change text of 'QLineEdit' in 'QSettings' and get on 'QPushButton's' call
我想在应用程序中保存/更改“ QLineEdit”文本,然后在某些特定位置使用“ QPushButton”再次获取。
The logic is to associate the information with a key, in the following example I show how the text is saved when the text is modified and then the text is retrieved by pressing the button. 逻辑是将信息与键相关联,在以下示例中,我演示了如何在修改文本后保存文本,然后通过按按钮检索文本。
from PySide2 import QtCore, QtWidgets
class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.m_le = QtWidgets.QLineEdit()
self.m_le.textChanged.connect(self.onTextChanged)
self.m_button = QtWidgets.QPushButton("Press Me")
self.m_button.clicked.connect(self.onClicked)
lay = QtWidgets.QVBoxLayout(self)
lay.addWidget(self.m_le)
lay.addWidget(self.m_button)
@QtCore.Slot(str)
def onTextChanged(self, text):
settings = QtCore.QSettings()
settings.setValue("text", text)
@QtCore.Slot()
def onClicked(self):
settings = QtCore.QSettings()
text = settings.value("text")
print(text)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.