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

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

    • <bdo id='SQ7yI'></bdo><ul id='SQ7yI'></ul>
    <legend id='SQ7yI'><style id='SQ7yI'><dir id='SQ7yI'><q id='SQ7yI'></q></dir></style></legend>

      <tfoot id='SQ7yI'></tfoot>

      1. <small id='SQ7yI'></small><noframes id='SQ7yI'>

        通過信號調用函數將默認鍵控參數更改為“Fals

        function call through signal changes default keyed arguments to #39;False#39;. Why?(通過信號調用函數將默認鍵控參數更改為“False.為什么?)

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

      2. <legend id='c4fbk'><style id='c4fbk'><dir id='c4fbk'><q id='c4fbk'></q></dir></style></legend>

            <tbody id='c4fbk'></tbody>
            <tfoot id='c4fbk'></tfoot>
                  <bdo id='c4fbk'></bdo><ul id='c4fbk'></ul>
                • <small id='c4fbk'></small><noframes id='c4fbk'>

                  本文介紹了通過信號調用函數將默認鍵控參數更改為“False".為什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  當通過信號連接調用函數時

                  mybutton.clicked.connect(myfunction)

                  調用該函數時,其所有參數都設置為 False.即使已設置默認參數.這是預期的行為嗎?

                  下面的代碼顯示了一個簡單的示例.對于我的特殊情況,將所有參數設置為 False 并不是一個大問題,因為我可以簡單地用 if 語句來捕捉它.但是,我認為了解為什么以這種方式實施它可能對進一步的項目有所幫助.

                  這個簡單的程序顯示了我所期望的行為.

                  def 函數(foo=None):打印(富)功能()

                  <塊引用>

                  但是,在這個最小的 Qt 示例中,函數參數不再是None",而是False".

                  導入系統從 PyQt5.QtWidgets 導入 QMainWindow、QGridLayout、QWidget、QPushButton、QApplication類主窗口(QMainWindow):def __init__(self):QMainWindow.__init__(self)centralWidget = QWidget(self)self.setCentralWidget(centralWidget)gridLayout = QGridLayout(self)centralWidget.setLayout(gridLayout)btn = QPushButton("按鈕",self)gridLayout.addWidget(btn)btn.clicked.connect(self.function)def 函數(自我,foo=None):打印(富)如果 __name__ == "__main__":應用程序 = QApplication(sys.argv)mainWin = MainWindow()mainWin.show()sys.exit(app.exec_())

                  <塊引用>

                  錯誤

                  我想,問題是:我是否必須忍受在我的函數中沒有可用的默認值(即,一旦我注意到它們被設置為 False,我是否需要重置它們)還是有任何更聰明的方法處理它?

                  解決方案

                  clicked是一個重載信號,即它們是2個同名信號不同簽名.

                  clicked = QtCore.pyqtSignal([], [bool])# 點擊 = QtCore.pyqtSignal()# clicked = QtCore.pyqtSignal(bool)

                  有關詳細信息,請閱讀此答案.

                  建立連接時,PyQt 確定將使用哪個信號,在這種情況下,您的函數的參數類似于第二種形式,因此信號將發送布爾值 False,在您的情況下,它將替換默認值.

                  如果您不希望這種情況發生,那么您必須使用 @QtCore.pyqtSlot() 裝飾器,以便它不會向您發送任何參數,因此您的函數使用默認參數.

                  導入系統從 PyQt5 導入 QtCore、QtWidgets類 MainWindow(QtWidgets.QMainWindow):def __init__(self, parent=None):超級(主窗口,自我).__init__(父)centralWidget = QtWidgets.QWidget()self.setCentralWidget(centralWidget)gridLayout = QtWidgets.QGridLayout(centralWidget)btn = QtWidgets.QPushButton("按鈕")gridLayout.addWidget(btn)btn.clicked.connect(self.function)@QtCore.pyqtSlot()def 函數(自我,foo=None):打印(富)如果 __name__ == "__main__":應用程序 = QtWidgets.QApplication(sys.argv)mainWin = MainWindow()mainWin.show()sys.exit(app.exec_())

                  輸出:

                  When calling a function via a signal connection as in

                  mybutton.clicked.connect(myfunction)
                  

                  the function is called with all its arguments set to False. Even though default arguments have been set. Is this the expected behavior?

                  The code below shows a simple example. For my particular case having all arguments set to False is not a big issue as I can simply catch it with an if statement. However I feel that knowledge on why it is implemented this way may be helpful for further projects.

                  This simple program shows the behavior I would expect.

                  def function(foo=None):
                      print(foo)
                  
                  function()
                  

                  None

                  With this minimal Qt example however, the functions argument is no longer 'None', but 'False'.

                  import sys
                  from PyQt5.QtWidgets import QMainWindow, QGridLayout, QWidget, QPushButton, QApplication
                  
                  class MainWindow(QMainWindow):
                      def __init__(self):
                          QMainWindow.__init__(self)
                          centralWidget = QWidget(self)
                          self.setCentralWidget(centralWidget)
                          gridLayout = QGridLayout(self)
                          centralWidget.setLayout(gridLayout)
                          btn = QPushButton("button",self)
                          gridLayout.addWidget(btn)
                          btn.clicked.connect(self.function)
                  
                      def function(self, foo=None):
                          print(foo)
                  
                  if __name__ == "__main__":
                      app = QApplication(sys.argv)
                      mainWin = MainWindow()
                      mainWin.show()
                      sys.exit( app.exec_() )
                  

                  False

                  The question, i guess, is: Do I have to live with no having the default values available in my functions (i.e. do I need to reset them once I notice that they were set to False) or is there any smarter way to handle it?

                  解決方案

                  clicked is an overloaded signal, that is, they are 2 signals with the same name and with different signatures.

                  clicked = QtCore.pyqtSignal([], [bool])
                  # clicked = QtCore.pyqtSignal()
                  # clicked = QtCore.pyqtSignal(bool)
                  

                  For more detail read this answer.

                  When the connection is made PyQt determines which of the signals will use, in this case the arguments of your function are similar to the second form so the signal will send the boolean False, and in your case it will replace the default value.

                  If you do not want that to happen then you must force PyQt to use the first form using the @QtCore.pyqtSlot() decorator so that it does not send you any parameter and therefore your function uses the default parameter.

                  import sys
                  from PyQt5 import QtCore, QtWidgets
                  
                  
                  class MainWindow(QtWidgets.QMainWindow):
                      def __init__(self, parent=None):
                          super(MainWindow, self).__init__(parent)
                          centralWidget = QtWidgets.QWidget()
                          self.setCentralWidget(centralWidget)
                          gridLayout = QtWidgets.QGridLayout(centralWidget)
                          btn = QtWidgets.QPushButton("button")
                          gridLayout.addWidget(btn)
                          btn.clicked.connect(self.function)
                  
                      @QtCore.pyqtSlot()
                      def function(self, foo=None):
                          print(foo)
                  
                  
                  if __name__ == "__main__":
                      app = QtWidgets.QApplication(sys.argv)
                      mainWin = MainWindow()
                      mainWin.show()
                      sys.exit(app.exec_())
                  

                  Output:

                  None
                  

                  這篇關于通過信號調用函數將默認鍵控參數更改為“False".為什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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時顯示進度條?)
                    <tbody id='qN6EM'></tbody>
                  <tfoot id='qN6EM'></tfoot>

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

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

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

                          • 主站蜘蛛池模板: 成人免费大片黄在线播放 | 欧美一区二区三区久久精品 | 亚洲视频区 | 国产精品视频播放 | 欧美日韩在线视频一区 | 日本不卡一区二区三区在线观看 | 日本一区二区三区四区 | 欧美成视频 | 男女午夜激情视频 | 免费看国产一级特黄aaaa大片 | 欧美综合久久久 | 91天堂网| 久久免费精品 | 看一级毛片视频 | 看片一区| 99久久精品免费视频 | 天天操天天怕 | 成人毛片视频在线播放 | 日韩中文一区二区三区 | 久草色视频 | 午夜看片网站 | 亚洲精品久久嫩草网站秘色 | 欧美日韩亚洲三区 | 色综合久 | 精品丝袜在线 | 欧美另类视频 | 国产精品国产a级 | 久久精品免费一区二区 | 国产69精品久久99不卡免费版 | 人人爽日日躁夜夜躁尤物 | 风间由美一区二区三区在线观看 | 51ⅴ精品国产91久久久久久 | 日韩有码一区二区三区 | 在线免费观看视频你懂的 | 成人国产精品一级毛片视频毛片 | 亚洲一区成人 | 日韩网| 波多野结衣一二三区 | 超碰网址| 免费一级毛片 | 91久久夜色精品国产网站 |