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

<legend id='Xdo2C'><style id='Xdo2C'><dir id='Xdo2C'><q id='Xdo2C'></q></dir></style></legend><tfoot id='Xdo2C'></tfoot>

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

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

      1. Qthread中的Python訪問父類的小部件

        Python access widgets of parent class in Qthread(Qthread中的Python訪問父類的小部件)
          <tbody id='8DmxX'></tbody>
          <bdo id='8DmxX'></bdo><ul id='8DmxX'></ul>

        • <tfoot id='8DmxX'></tfoot>

              <legend id='8DmxX'><style id='8DmxX'><dir id='8DmxX'><q id='8DmxX'></q></dir></style></legend>

                • <small id='8DmxX'></small><noframes id='8DmxX'>

                  <i id='8DmxX'><tr id='8DmxX'><dt id='8DmxX'><q id='8DmxX'><span id='8DmxX'><b id='8DmxX'><form id='8DmxX'><ins id='8DmxX'></ins><ul id='8DmxX'></ul><sub id='8DmxX'></sub></form><legend id='8DmxX'></legend><bdo id='8DmxX'><pre id='8DmxX'><center id='8DmxX'></center></pre></bdo></b><th id='8DmxX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8DmxX'><tfoot id='8DmxX'></tfoot><dl id='8DmxX'><fieldset id='8DmxX'></fieldset></dl></div>
                • 本文介紹了Qthread中的Python訪問父類的小部件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想訪問QThread類中的父類小部件

                  I want to access the parent class widgets in the QThread class

                  這一行給出了掛起 GUI "Example().setWindowTitle("Window")"

                  This line gives hangs GUI "Example().setWindowTitle("Window")"

                  我該怎么做?

                  class Example(QWidget):
                      def __init__(self):
                          super().__init__()
                          self.myclass2 = myclass2()
                          self.myclass2.start()
                          self.initUI()
                  
                      def initUI(self):
                          self.setGeometry(300, 300, 300, 220)
                          self.setWindowTitle('Icon')
                          self.setWindowIcon(QIcon('web.png'))
                          self.show()
                  
                  
                  class myclass2(QThread):
                      def __init__(self, parent=None):
                          super(myclass2, self).__init__(parent)
                  
                      def run(self):
                          while True:
                              time.sleep(.1)
                              print(" in thread 
                  ")
                              Example().setWindowTitle("Window")
                  
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                      ex = Example()
                      sys.exit(app.exec_())
                  

                  推薦答案

                  你必須明白下面的表達:

                  You must understand the following expression:

                  Example().setWindowTitle("Window")
                  

                  相當于:

                  obj = Example()
                  obj.setWindowTitle("Window")
                  

                  也就是說,您正在創建除 ex = Example() 之外的另一個 Example 對象,并且該對象正在創建另一個 myclass2 對象,以及另一個 myclass2 對象正在創建另一個示例,并且顯然正在創建一個無限循環.

                  That is, you are creating another Example object other than ex = Example(), and that object is creating another myclass2 object, and that other myclass2 object is creating another Example, and an infinite loop is clearly being created.

                  將來可能給您帶來問題的另一件事是為不同的事物建立相同的名稱,雖然在這種情況下這不是問題但在將來的情況下可能會給您帶來問題,我參考的代碼是:

                  Another thing that in the future could cause you problems is to establish the same name for different things, although in this case it is not a problem but in future occasions it could bring you problems, the code to which I refer is:

                  self.myclass2 = myclass2()
                  

                  例如,建議類應以大寫字母開頭.

                  For example, it is recommended that classes should start with capital letters.

                  另一個僅在 Qt 中有效的錯誤是不能在主線程以外的線程中創建或操作 GUI.所以你不能直接在另一個線程中更改標題,但有兩種方法:

                  Another error that is valid only in Qt is that the GUI can not be created or manipulated in a thread other than the main thread. So you can not change the title directly in the other thread but there are 2 methods:

                  但是為此我們必須通過一個屬性來傳遞 GUI:

                  But for this we must pass the GUI through a property:

                  class Example(QWidget):
                      def __init__(self):
                          super().__init__()
                          self.myclass2 = MyClass()
                          self.myclass2.gui = self
                          self.myclass2.start()
                          self.initUI()
                  
                      def initUI(self):
                          self.setGeometry(300, 300, 300, 220)
                          self.setWindowTitle('Icon')
                          self.setWindowIcon(QIcon('web.png'))
                          self.show()
                  
                  
                  class MyClass(QThread):
                      def run(self):
                          while True:
                              time.sleep(.1)
                              print(" in thread 
                  ")
                              QMetaObject.invokeMethod(self.gui, "setWindowTitle", Qt.QueuedConnection, Q_ARG(str, "Window"))
                  

                  2.信號與插槽

                  class Example(QWidget):
                      def __init__(self):
                          super().__init__()
                          self.myclass2 = MyClass()
                          self.myclass2.titleChanged.connect(self.setWindowTitle)
                          self.myclass2.start()
                          self.initUI()
                  
                      def initUI(self):
                          self.setGeometry(300, 300, 300, 220)
                          self.setWindowTitle('Icon')
                          self.setWindowIcon(QIcon('web.png'))
                          self.show()
                  
                  
                  class MyClass(QThread):
                      titleChanged = pyqtSignal(str)
                  
                      def run(self):
                          while True:
                              time.sleep(.1)
                              print(" in thread 
                  ")
                              self.titleChanged.emit("Window")
                  

                  加:

                  您不應該直接從線程修改 GUI,而是通過信號發送數據:

                  You should not modify the GUI from the thread directly but send the data through a signal:

                  import sys
                  
                  from PyQt5 import QtCore, QtGui, QtWidgets
                  
                  class Example(QtWidgets.QWidget):
                      def __init__(self):
                          super().__init__()
                          lay = QtWidgets.QVBoxLayout(self)
                          le = QtWidgets.QLineEdit()
                          lay.addWidget(le)
                          self.myclass2 = MyClass()
                          self.myclass2.titleChanged.connect(self.setWindowTitle)
                          self.myclass2.infoChanged.connect(le.setText) # <-- connect signal
                          self.myclass2.start()
                          self.initUI()
                  
                      def initUI(self):
                          self.setGeometry(300, 300, 300, 220)
                          self.setWindowTitle('Icon')
                          self.setWindowIcon(QtGui.QIcon('web.png'))
                          self.show()
                  
                  
                  class MyClass(QtCore.QThread):
                      titleChanged = QtCore.pyqtSignal(str)
                      infoChanged = QtCore.pyqtSignal(str) # <-- create signal
                  
                      def run(self):
                          counter = 0
                          while True:
                              QtCore.QThread.msleep(100)
                              print(" in thread 
                  ")
                              self.titleChanged.emit("Window")
                              self.infoChanged.emit("{}".format(counter)) # <-- emit signal
                              counter += 1
                  
                  
                  if __name__ == '__main__':
                      app = QtWidgets.QApplication(sys.argv)
                      ex = Example()
                      sys.exit(app.exec_())
                  

                  這篇關于Qthread中的Python訪問父類的小部件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='bcHEs'></bdo><ul id='bcHEs'></ul>
                        <tbody id='bcHEs'></tbody>

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

                          <legend id='bcHEs'><style id='bcHEs'><dir id='bcHEs'><q id='bcHEs'></q></dir></style></legend>
                          • <tfoot id='bcHEs'></tfoot>

                          • <i id='bcHEs'><tr id='bcHEs'><dt id='bcHEs'><q id='bcHEs'><span id='bcHEs'><b id='bcHEs'><form id='bcHEs'><ins id='bcHEs'></ins><ul id='bcHEs'></ul><sub id='bcHEs'></sub></form><legend id='bcHEs'></legend><bdo id='bcHEs'><pre id='bcHEs'><center id='bcHEs'></center></pre></bdo></b><th id='bcHEs'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='bcHEs'><tfoot id='bcHEs'></tfoot><dl id='bcHEs'><fieldset id='bcHEs'></fieldset></dl></div>
                            主站蜘蛛池模板: 国产欧美在线播放 | 操网站| 精品国产欧美日韩不卡在线观看 | 一级a性色生活片久久毛片 一级特黄a大片 | 国产一级毛片精品完整视频版 | 97超碰免费 | 情侣av | 免费在线观看黄视频 | aaa天堂| 亚洲国产精品一区在线观看 | 午夜男人的天堂 | 人人九九精 | 国产一区二区三区久久久久久久久 | 奇米影视首页 | 99综合 | 黄片毛片在线观看 | 欧美一级二级视频 | 国产精品美女久久久久久不卡 | 欧美日韩国产一区二区三区 | 九九综合 | 欧美精品99 | 在线久草| 一级黄色大片 | 国产精品久久久久影院色老大 | 欧美激情99 | 午夜看片网站 | 毛片免费观看 | a级黄色毛片免费播放视频 国产精品视频在线观看 | 1级黄色大片 | av性色全交蜜桃成熟时 | 久久成人国产 | 日韩一三区 | 久久久久久国产免费视网址 | 精品久久国产 | 亚洲一区二区三区福利 | 欧美一区二区免费在线 | 99一级毛片 | 欧美自拍第一页 | 亚洲国产成人av好男人在线观看 | 欧美精品一二三区 | 中文字幕视频网 |