久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

          <bdo id='3kMhP'></bdo><ul id='3kMhP'></ul>
        <tfoot id='3kMhP'></tfoot><legend id='3kMhP'><style id='3kMhP'><dir id='3kMhP'><q id='3kMhP'></q></dir></style></legend>

        <small id='3kMhP'></small><noframes id='3kMhP'>

      1. <i id='3kMhP'><tr id='3kMhP'><dt id='3kMhP'><q id='3kMhP'><span id='3kMhP'><b id='3kMhP'><form id='3kMhP'><ins id='3kMhP'></ins><ul id='3kMhP'></ul><sub id='3kMhP'></sub></form><legend id='3kMhP'></legend><bdo id='3kMhP'><pre id='3kMhP'><center id='3kMhP'></center></pre></bdo></b><th id='3kMhP'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='3kMhP'><tfoot id='3kMhP'></tfoot><dl id='3kMhP'><fieldset id='3kMhP'></fieldset></dl></div>
      2. 即使小部件關閉,如何在 PyQt 中的 QLineEdits 中保

        How to save text in QLineEdits in PyQt even if the Widget gets closed?(即使小部件關閉,如何在 PyQt 中的 QLineEdits 中保存文本?)
          1. <small id='NoECZ'></small><noframes id='NoECZ'>

            • <legend id='NoECZ'><style id='NoECZ'><dir id='NoECZ'><q id='NoECZ'></q></dir></style></legend>
              • <bdo id='NoECZ'></bdo><ul id='NoECZ'></ul>
                  <tbody id='NoECZ'></tbody>
              • <i id='NoECZ'><tr id='NoECZ'><dt id='NoECZ'><q id='NoECZ'><span id='NoECZ'><b id='NoECZ'><form id='NoECZ'><ins id='NoECZ'></ins><ul id='NoECZ'></ul><sub id='NoECZ'></sub></form><legend id='NoECZ'></legend><bdo id='NoECZ'><pre id='NoECZ'><center id='NoECZ'></center></pre></bdo></b><th id='NoECZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='NoECZ'><tfoot id='NoECZ'></tfoot><dl id='NoECZ'><fieldset id='NoECZ'></fieldset></dl></div>
                <tfoot id='NoECZ'></tfoot>

                  本文介紹了即使小部件關閉,如何在 PyQt 中的 QLineEdits 中保存文本?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  您好,我已經使用 PyQt 為我的腳本制作了一個 GUI,我有幾個行編輯和幾個按鈕

                  Hello I have made a GUI for my script using PyQt I have a couple of Line edit ands a couple of buttons

                  (.....) = (self.(.....).text()) 我將該文本用于我的腳本作為變量(但我認為這對問題并不重要)我希望能夠在 QLineEdits 中輸入文本并保存它,所以下次我打開它時,文本仍然存在

                  (.....) = (self.(.....).text()) which I use that text for my script as a variable (but I don't think thats important to the question) I want to be able to type text into the QLineEdits and for it to save so next time I open it the text will still be there

                  我使用 PyQt5 然后我使用 Py-installer 將它變成一個應用程序所以我希望能夠將文本保存在 QLineEdits 中,然后當它關閉時保存在那里以備下次打開它>

                  I use PyQt5 then I use Py-installer to make it into an app So I want to be able to save the text inside the QLineEdits and then when It closes for it be be saved there for next time I open it>

                  附言.我正在與其他人共享這個應用程序所以我希望它保存用戶輸入的內容(他們正在輸入他們自定義的東西,例如(名稱或類似的東西)

                  Ps. I am sharing this app with other people So I want it to save what that user puts in (they are putting in stuff that is custom to them like for example (name or something like that)

                  這是我的 pyqt5 代碼示例:

                  Here is a sample of my pyqt5 code:

                  推薦答案

                  對于較老的應用程序,它實現了保存和恢復小部件狀態的功能.

                  For an older application, it implements the functions that saved the states of the widgets and restored them.

                  為了使其正常工作,應用程序必須滿足以下要求:

                  In order for it to work properly, the application must meet the following requirements:

                  • 您必須設置 OrganizationNameOrganizationDomainApplicationName.

                  您要保存狀態的每個小部件都必須有一個 objectName

                  Each widget that you want to save the state must have an objectName

                  當你想恢復狀態時,你必須使用 restore(),一個不錯的選擇是在創建所有的小部件之后.

                  You must use restore() when you want to restore the states, a good option is after creating all the widgets.

                  當你想保存狀態時,你必須使用save(),一個好地方是closeEvent().

                  You must use save() when you want to save the states, a good place would be closeEvent().

                  在下一部分中,我將展示一個示例:

                  In the next part I show an example:

                  import sys
                  
                  from PyQt5 import QtWidgets, QtCore
                  
                  # for PyQt4 change QtWidget to QtGui and PyQt5 to PyQt4
                  
                  
                  def restore(settings):
                      finfo = QtCore.QFileInfo(settings.fileName())
                      if finfo.exists() and finfo.isFile():
                          for w in QtWidgets.qApp.allWidgets():
                              mo = w.metaObject()
                              if w.objectName() and not w.objectName().startswith("qt_"):
                                  settings.beginGroup(w.objectName())
                                  for i in range( mo.propertyCount(), mo.propertyOffset()-1, -1):
                                      prop = mo.property(i)
                                      if prop.isWritable():
                                          name = prop.name()
                                          val = settings.value(name, w.property(name))
                                          if str(val).isdigit():
                                              val = int(val)
                                          w.setProperty(name, val)
                                  settings.endGroup()
                  
                  def save(settings):
                      for w in QtWidgets.qApp.allWidgets():
                          mo = w.metaObject()
                          if w.objectName() and not w.objectName().startswith("qt_"):
                              settings.beginGroup(w.objectName())
                              for i in range(mo.propertyCount()):
                                  prop = mo.property(i)
                                  name = prop.name()
                                  if prop.isWritable():
                                      settings.setValue(name, w.property(name))
                              settings.endGroup()
                  
                  
                  class Widget(QtWidgets.QWidget):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self.setObjectName("widget")
                          self.init_ui()
                          self.settings = QtCore.QSettings()
                          print(self.settings.fileName())
                          restore(self.settings)
                  
                      def init_ui(self):
                          lay = QtWidgets.QVBoxLayout(self)
                          lineEdit1 = QtWidgets.QLabel("label")
                          lineEdit1.setObjectName("label")
                          lineEdit2 = QtWidgets.QLineEdit()
                          lineEdit2.setObjectName("lineEdit2")
                          combobox = QtWidgets.QComboBox()
                          combobox.addItems(["1", "2", "3"])
                          combobox.setObjectName("combo")
                          lay.addWidget(lineEdit1)
                          lay.addWidget(lineEdit2)
                          lay.addWidget(combobox)
                  
                      def closeEvent(self, event):
                          save(self.settings)
                          super().closeEvent(event)
                  
                  
                  if __name__ == '__main__':
                      app = QtWidgets.QApplication(sys.argv)
                      QtCore.QCoreApplication.setOrganizationName("Eyllanesc")
                      QtCore.QCoreApplication.setOrganizationDomain("eyllanesc.com")
                      QtCore.QCoreApplication.setApplicationName("MyApp")
                      ex = Widget()
                      ex.show()
                      sys.exit(app.exec_())
                  

                  <小時>

                  更新:

                  如果您使用 Qt Designer,則不再需要放置 objectsName,因為它們已經建立,但另一方面,提供 Qt Designer 的類不是小部件,而是一個負責填充小部件的類,因此我們必須創建小部件才能覆蓋 closeEvent 方法,如下所示:

                  In the case that you use Qt Designer it is no longer necessary to place the objectsNames because they are already established, but on the other hand the class that provides Qt Designer is not a widget, but a class that is responsible for filling a widget, so we must create the widget to be able to overwrite the closeEvent method as shown below:

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  class Ui_MainWindow(object):
                      def setupUi(self, MainWindow):
                          ...
                      def retranslateUi(self, MainWindow):
                          ...
                  
                  class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
                      def __init__(self, *args, **kwargs):
                          super().__init__(*args, **kwargs)
                          self.setupUi(self)
                          self.settings = QtCore.QSettings()
                          restore(self.settings)
                  
                      def closeEvent(self, event):
                          save(self.settings)
                          super().closeEvent(event)
                  
                  if __name__ == "__main__":
                      import sys
                      app = QtWidgets.QApplication(sys.argv)
                      QtCore.QCoreApplication.setOrganizationName("Eyllanesc")
                      QtCore.QCoreApplication.setOrganizationDomain("eyllanesc.com")
                      QtCore.QCoreApplication.setApplicationName("MyApp")
                      w = MainWindow()
                      w.show()
                      sys.exit(app.exec_())
                  

                  這篇關于即使小部件關閉,如何在 PyQt 中的 QLineEdits 中保存文本?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                    <bdo id='UbQoR'></bdo><ul id='UbQoR'></ul>

                    <small id='UbQoR'></small><noframes id='UbQoR'>

                    <tfoot id='UbQoR'></tfoot>
                      <tbody id='UbQoR'></tbody>

                        • <legend id='UbQoR'><style id='UbQoR'><dir id='UbQoR'><q id='UbQoR'></q></dir></style></legend>
                          1. <i id='UbQoR'><tr id='UbQoR'><dt id='UbQoR'><q id='UbQoR'><span id='UbQoR'><b id='UbQoR'><form id='UbQoR'><ins id='UbQoR'></ins><ul id='UbQoR'></ul><sub id='UbQoR'></sub></form><legend id='UbQoR'></legend><bdo id='UbQoR'><pre id='UbQoR'><center id='UbQoR'></center></pre></bdo></b><th id='UbQoR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='UbQoR'><tfoot id='UbQoR'></tfoot><dl id='UbQoR'><fieldset id='UbQoR'></fieldset></dl></div>

                            主站蜘蛛池模板: 密室大逃脱第六季大神版在线观看 | 国产黄色在线 | 亚洲一区二区视频 | 国产在线精品一区二区 | 亚洲精品视频观看 | 久久久国产一区二区三区 | 国产精品免费在线 | 羞羞在线视频 | 午夜免费视频 | 亚洲欧洲精品一区 | 久久久亚洲一区 | 黑人巨大精品欧美一区二区免费 | 羞羞色在线观看 | 天堂久久天堂综合色 | 国产精品久久 | 亚洲精品乱码久久久久久按摩观 | 天天综合操 | 逼逼网| 国产精品亚洲综合 | 欧美性网 | 欧美久久久久久久久 | 欧美电影免费观看 | 亚洲精品一区av在线播放 | 99热播精品| 一区二区三区国产 | 久久精品一区二区三区四区 | 久久香焦| 国产激情一区二区三区 | 99热精品久久 | 一区二区三区av | 黄色一级大片在线观看 | 91在线一区二区 | 成人在线免费视频观看 | 国内精品久久久久久 | 国产黄色大片在线免费观看 | 乱码av午夜噜噜噜噜动漫 | 成人免费观看视频 | 天天操操 | 91精品国产综合久久久亚洲 | a级免费观看视频 | jizz中国日本 |