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

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

      1. <tfoot id='biqTy'></tfoot>

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

        PyQt 正確使用 emit() 和 pyqtSignal()

        PyQt proper use of emit() and pyqtSignal()(PyQt 正確使用 emit() 和 pyqtSignal())
      2. <small id='gJXpc'></small><noframes id='gJXpc'>

      3. <legend id='gJXpc'><style id='gJXpc'><dir id='gJXpc'><q id='gJXpc'></q></dir></style></legend>

              <tbody id='gJXpc'></tbody>
              <bdo id='gJXpc'></bdo><ul id='gJXpc'></ul>
              1. <tfoot id='gJXpc'></tfoot>

                <i id='gJXpc'><tr id='gJXpc'><dt id='gJXpc'><q id='gJXpc'><span id='gJXpc'><b id='gJXpc'><form id='gJXpc'><ins id='gJXpc'></ins><ul id='gJXpc'></ul><sub id='gJXpc'></sub></form><legend id='gJXpc'></legend><bdo id='gJXpc'><pre id='gJXpc'><center id='gJXpc'></center></pre></bdo></b><th id='gJXpc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gJXpc'><tfoot id='gJXpc'></tfoot><dl id='gJXpc'><fieldset id='gJXpc'></fieldset></dl></div>
                  本文介紹了PyQt 正確使用 emit() 和 pyqtSignal()的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在閱讀有關(guān) PyQt5 的一些文檔,以提出一個簡單的信號槽機(jī)制.由于設(shè)計考慮,我已經(jīng)停下來了.

                  考慮以下代碼:

                  導(dǎo)入系統(tǒng)從 PyQt5.QtCore 導(dǎo)入 (Qt, pyqtSignal)從 PyQt5.QtWidgets 導(dǎo)入(QWidget、QLCDNumber、QSlider、QVBoxLayout, QApplication)類示例(QWidget):def __init__(self):超級().__init__()self.initUI()def printLabel(self, str):打印(字符串)定義日志標(biāo)簽(自我,str):'''記錄到文件'''經(jīng)過定義 initUI(自我):lcd = QLCDNumber(self)sld = QSlider(Qt.Horizo??ntal, self)vbox = QVBoxLayout()vbox.addWidget(lcd)vbox.addWidget(sld)self.setLayout(vbox)#冗余連接sld.valueChanged.connect(lcd.display)sld.valueChanged.connect(self.printLabel)sld.valueChanged.connect(self.logLabel)self.setGeometry(300, 300, 250, 150)self.setWindowTitle('信號和槽')自我展示()如果 __name__ == '__main__':應(yīng)用程序 = QApplication(sys.argv)ex = 示例()sys.exit(app.exec_())

                  要跟蹤對滑塊所做的更改,我只需打印并記錄所做的更改.我不喜歡代碼的地方是我需要調(diào)用 sld.valueChanged 插槽三次以將相同的信息發(fā)送到 3 個不同的插槽.

                  是否可以創(chuàng)建我自己的 pyqtSignal 將整數(shù)發(fā)送到單個插槽函數(shù).反過來讓槽函數(shù)發(fā)出需要進(jìn)行的更改?

                  • 也許我不完全理解 emit() 的用途,因?yàn)樵?PyQt Signal-Slot 文檔.我們給出的只是一個如何實(shí)現(xiàn)不帶參數(shù)的 emit 的示例.

                  我想做的是創(chuàng)建一個處理發(fā)射函數(shù)的函數(shù).考慮以下幾點(diǎn):

                  導(dǎo)入系統(tǒng)從 PyQt5.QtCore 導(dǎo)入 (Qt, pyqtSignal)從 PyQt5.QtWidgets 導(dǎo)入(QWidget、QLCDNumber、QSlider、QVBoxLayout, QApplication)類示例(QWidget):def __init__(self):超級().__init__()#創(chuàng)建信號self.val_Changed = pyqtSignal(int, name='valChanged')self.initUI()定義 initUI(自我):lcd = QLCDNumber(self)sld = QSlider(Qt.Horizo??ntal, self)vbox = QVBoxLayout()vbox.addWidget(lcd)vbox.addWidget(sld)self.setLayout(vbox)sld.val_Changed.connect(self.handle_LCD)self.val_Changed.emit()self.setGeometry(300, 300, 250, 150)self.setWindowTitle('信號和槽')自我展示()def handle_LCD(自我,文本):'''日志'''打印(文本)'''將 val_Changed 連接到 lcd.display'''如果 __name__ == '__main__':應(yīng)用程序 = QApplication(sys.argv)ex = 示例()sys.exit(app.exec_())

                  這里顯然存在一些嚴(yán)重的設(shè)計缺陷.我無法理解函數(shù)調(diào)用的順序.而且我沒有正確實(shí)現(xiàn) pyqtSignal .不過,我確實(shí)相信正確陳述以下 3 點(diǎn)將有助于我制作出合適的應(yīng)用程序:

                  1. 對于預(yù)定義的信號:將信號發(fā)送到槽函數(shù).可以重新實(shí)現(xiàn) Slot 以使用信號值.
                  2. 生成帶有一些參數(shù)的 pyqtSignal 對象.目前尚不清楚這些參數(shù)的用途是什么以及它們與發(fā)射"參數(shù)有何不同.
                  3. emit 可以重新實(shí)現(xiàn)以將特定的信號值發(fā)送到槽函數(shù).目前還不清楚為什么我需要發(fā)送與以前存在的信號方法不同的值.

                  隨意完全改變我正在嘗試做的代碼,因?yàn)槲疫€沒有弄清楚它是否屬于良好的風(fēng)格.

                  解決方案

                  您可以定義自己的插槽(任何 python 可調(diào)用)并將其連接到信號,然后從該插槽調(diào)用其他插槽.

                  類示例(QWidget):def __init__(self):超級().__init__()self.initUI()def printLabel(self, str):打印(字符串)定義日志標(biāo)簽(自我,str):'''記錄到文件'''經(jīng)過@QtCore.pyqtSlot(int)def on_sld_valueChanged(自我,價值):self.lcd.display(值)self.printLabel(值)self.logLabel(值)定義 initUI(自我):self.lcd = QLCDNumber(self)self.sld = QSlider(Qt.Horizo??ntal, self)vbox = QVBoxLayout()vbox.addWidget(self.lcd)vbox.addWidget(self.sld)self.setLayout(vbox)self.sld.valueChanged.connect(self.on_sld_valueChanged)self.setGeometry(300, 300, 250, 150)self.setWindowTitle('信號和槽')

                  另外,如果你想定義自己的信號,它們必須定義為類變量

                  類示例(QWidget):my_signal = pyqtSignal(int)

                  pyqtSignal 的參數(shù)定義了將在該信號上發(fā)出的對象類型,因此在這種情況下,您可以這樣做

                  self.my_signal.emit(1)

                  <塊引用>

                  emit 可以重新實(shí)現(xiàn)以將特定的信號值發(fā)送到插槽功能.目前還不清楚為什么我需要發(fā)送不同的來自先前存在的信號方法的值.

                  您通常不應(yīng)該發(fā)出內(nèi)置信號.您應(yīng)該只需要發(fā)出您定義的信號.定義信號時,可以定義不同類型的不同簽名,插槽可以選擇要連接的簽名.例如,您可以這樣做

                  my_signal = pyqtSignal([int], [str])

                  這將定義一個具有兩個不同簽名的信號,并且一個插槽可以連接到任何一個

                  @pyqtSlot(int)def on_my_signal_int(自我,價值):斷言 isinstance(值,int)@pyqtSlot(str)def on_my_signal_str(自我,價值):斷言 isinstance(值,str)

                  在實(shí)踐中,我很少重載信號簽名.我通常只會創(chuàng)建兩個具有不同簽名的單獨(dú)信號,而不是重載相同的信號.但它存在并在 PyQt 中得到支持,因?yàn)?Qt 具有以這種方式重載的信號(例如 QComboBox.currentIndexChanged)

                  I am reading through some documentation on PyQt5 to come up with a simple signal-slot mechanism. I have come to a halt due to a design consideration.

                  Consider the following code:

                  import sys
                  from PyQt5.QtCore import (Qt, pyqtSignal)
                  from PyQt5.QtWidgets import (QWidget, QLCDNumber, QSlider,
                      QVBoxLayout, QApplication)
                  
                  
                  class Example(QWidget):
                  
                      def __init__(self):
                          super().__init__()
                  
                          self.initUI()
                  
                      def printLabel(self, str):
                          print(str)
                  
                      def logLabel(self, str):
                          '''log to a file'''
                          pass
                  
                      def initUI(self):
                  
                          lcd = QLCDNumber(self)
                          sld = QSlider(Qt.Horizontal, self)
                  
                          vbox = QVBoxLayout()
                          vbox.addWidget(lcd)
                          vbox.addWidget(sld)
                  
                          self.setLayout(vbox)
                  
                          #redundant connections
                          sld.valueChanged.connect(lcd.display)
                          sld.valueChanged.connect(self.printLabel)
                          sld.valueChanged.connect(self.logLabel)
                  
                          self.setGeometry(300, 300, 250, 150)
                          self.setWindowTitle('Signal & slot')
                          self.show()
                  
                  
                  if __name__ == '__main__':
                  
                      app = QApplication(sys.argv)
                      ex = Example()
                      sys.exit(app.exec_())
                  

                  To track the changes made to the slider, I simply print and log the changes made. What I do not like about the code is that I am required to call the sld.valueChanged slot thrice to send the same information to 3 different slots.

                  Is it possible to create my own pyqtSignal that sends an integer to a single slot function. And in turn have the slot function emit the changes that need to be made?

                  • Maybe I don't fully understand the purpose of emit() because there are no good examples of it's purpose in the PyQt Signal-Slot docs. All we're given is an example of how to implement an emit with no parameters.

                  What I would like to do is create a function that handles the emit function. Consider the following:

                  import sys
                  from PyQt5.QtCore import (Qt, pyqtSignal)
                  from PyQt5.QtWidgets import (QWidget, QLCDNumber, QSlider,
                      QVBoxLayout, QApplication)
                  
                  
                  class Example(QWidget):
                  
                      def __init__(self):
                          super().__init__()
                  
                          #create signal
                          self.val_Changed = pyqtSignal(int, name='valChanged')
                  
                          self.initUI()
                  
                      def initUI(self):
                  
                          lcd = QLCDNumber(self)
                          sld = QSlider(Qt.Horizontal, self)
                  
                          vbox = QVBoxLayout()
                          vbox.addWidget(lcd)
                          vbox.addWidget(sld)
                  
                          self.setLayout(vbox)
                  
                          sld.val_Changed.connect(self.handle_LCD)
                          self.val_Changed.emit()
                  
                          self.setGeometry(300, 300, 250, 150)
                          self.setWindowTitle('Signal & slot')
                          self.show()
                  
                      def handle_LCD(self, text):
                          '''log'''
                          print(text)
                          '''connect val_Changed to lcd.display'''
                  
                  if __name__ == '__main__':
                  
                      app = QApplication(sys.argv)
                      ex = Example()
                      sys.exit(app.exec_())
                  

                  There are obviously some serious design flaws here. I cannot wrap my head around the order of function calls. And I am not implementing pyqtSignal correctly. I do however believe that correctly stating the following 3 points will help me produce a proper app:

                  1. For a predefined signal: send the signal to the slot function. Slot can be reimplemented to use the signal values.
                  2. Produce pyqtSignal object with some parameters. It is not yet clear what the purpose of these parameters are and how they differ from 'emit' parameters.
                  3. emit can be reimplemented to send specific signal values to the slot function. It is also not yet clear why I would need to send different values from previously existing signal methods.

                  Feel free to completely alter the code for what I am trying to do because I have not yet figured out if its in the realm of good style.

                  解決方案

                  You can define your own slot (any python callable) and connect that to the signal, then call the other slots from that one slot.

                  class Example(QWidget):
                  
                      def __init__(self):
                          super().__init__()
                          self.initUI()
                  
                      def printLabel(self, str):
                          print(str)
                  
                      def logLabel(self, str):
                          '''log to a file'''
                          pass
                  
                      @QtCore.pyqtSlot(int)
                      def on_sld_valueChanged(self, value):
                          self.lcd.display(value)
                          self.printLabel(value)
                          self.logLabel(value)
                  
                      def initUI(self):
                  
                          self.lcd = QLCDNumber(self)
                          self.sld = QSlider(Qt.Horizontal, self)
                  
                          vbox = QVBoxLayout()
                          vbox.addWidget(self.lcd)
                          vbox.addWidget(self.sld)
                  
                          self.setLayout(vbox)
                          self.sld.valueChanged.connect(self.on_sld_valueChanged)
                  
                  
                          self.setGeometry(300, 300, 250, 150)
                          self.setWindowTitle('Signal & slot')
                  

                  Also, if you want to define your own signals, they have to be defined as class variables

                  class Example(QWidget):
                      my_signal = pyqtSignal(int)
                  

                  The arguments to pyqtSignal define the types of objects that will be emit'd on that signal, so in this case, you could do

                  self.my_signal.emit(1)
                  

                  emit can be reimplemented to send specific signal values to the slot function. It is also not yet clear why I would need to send different values from previously existing signal methods.

                  You generally shouldn't be emitting the built in signals. You should only need to emit signals that you define. When defining a signal, you can define different signatures with different types, and slots can choose which signature they want to connect to. For instance, you could do this

                  my_signal = pyqtSignal([int], [str])
                  

                  This will define a signal with two different signatures, and a slot could connect to either one

                  @pyqtSlot(int)
                  def on_my_signal_int(self, value):
                      assert isinstance(value, int)
                  
                  @pyqtSlot(str)
                  def on_my_signal_str(self, value):
                      assert isinstance(value, str)
                  

                  In practice, I rarely overload signal signatures. I would normally just create two separate signals with different signatures rather than overloading the same signal. But it exists and is supported in PyQt because Qt has signals that are overloaded this way (eg. QComboBox.currentIndexChanged)

                  這篇關(guān)于PyQt 正確使用 emit() 和 pyqtSignal()的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進(jìn)度躍升至 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 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動時,yaxis 刻度標(biāo)簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進(jìn)度條?)

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

                    1. <legend id='qhPcQ'><style id='qhPcQ'><dir id='qhPcQ'><q id='qhPcQ'></q></dir></style></legend>

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

                            <bdo id='qhPcQ'></bdo><ul id='qhPcQ'></ul>
                          • <small id='qhPcQ'></small><noframes id='qhPcQ'>

                          • 主站蜘蛛池模板: 国产在线不卡视频 | 欧美精品一 | 国产伦理一区二区 | 久久久二区 | 亚洲一级特黄 | 欧美日韩一区二区在线 | 亚洲午夜精品 | 亚洲精品91天天久久人人 | 毛片av在线| 精品免费国产 | 久久午夜影院 | a视频| 毛片毛片毛片毛片毛片 | 免费毛片网 | 91久久精品日日躁夜夜躁欧美 | 久久天堂网 | 成人在线视频观看 | 五月婷婷综合网 | 欧美区日韩区 | 五月天婷婷社区 | 中文字幕伊人 | 男女操网站 | 亚洲福利在线观看 | 成年人黄色片 | 黄色一极片 | 天天干在线观看 | 国产成人精品毛片 | 午夜在线国语中文字幕视频 | 午夜精品在线 | 综合av网| 久久精品一二三 | www中文字幕 | 国产精品一区二 | 国产综合久久 | 成人黄色免费视频 | 日韩小视频 | 在线免费看毛片 | 免费视频a | 欧美黄色一级 | 一区二区色 | 少妇高潮露脸国语对白 |