pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <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="jtzxhjl" 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="fjnlp7z" 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="pn5vjxt" id='qN6EM'><tfoot id='qN6EM'></tfoot><dl id='qN6EM'><fieldset id='qN6EM'></fieldset></dl></div>
                          • <bdo id='qN6EM'></bdo><ul id='qN6EM'></ul>

                          • 主站蜘蛛池模板: 高硼硅玻璃|水位计玻璃板|光学三棱镜-邯郸奥维玻璃科技有限公司 高温高压釜(氢化反应釜)百科 | 上海单片机培训|重庆曙海培训分支机构—CortexM3+uC/OS培训班,北京linux培训,Windows驱动开发培训|上海IC版图设计,西安linux培训,北京汽车电子EMC培训,ARM培训,MTK培训,Android培训 | 快速门厂家-快速卷帘门-工业快速门-硬质快速门-西朗门业 | 石英陶瓷,石英坩埚,二氧化硅陶瓷-淄博百特高新材料有限公司 | 锂电池生产厂家-电动自行车航模无人机锂电池定制-世豹新能源 | RTO换向阀_VOC高温阀门_加热炉切断阀_双偏心软密封蝶阀_煤气蝶阀_提升阀-湖北霍科德阀门有限公司 | 视觉检测设备_自动化检测设备_CCD视觉检测机_外观缺陷检测-瑞智光电 | 压片机_高速_单冲_双层_花篮式_多功能旋转压片机-上海天九压片机厂家 | 档案密集柜_手动密集柜_智能密集柜_内蒙古档案密集柜-盛隆柜业内蒙古密集柜直销中心 | 卫生型双针压力表-高温防腐差压表-安徽康泰电气有限公司 | 超声波反应釜【百科】-以马内利仪器 | 杜甫仪器官网|实验室平行反应器|升降水浴锅|台式低温循环泵 | 螺纹三通快插接头-弯通快插接头-宁波舜驰气动科技有限公司 | 高效复合碳源-多核碳源生产厂家-污水处理反硝化菌种一长隆科技库巴鲁 | 发光字|标识设计|标牌制作|精神堡垒 - 江苏苏通广告有限公司 | 横河变送器-横河压力变送器-EJA变送器-EJA压力变送器-「泉蕴仪表」 | 洛阳防爆合格证办理-洛阳防爆认证机构-洛阳申请国家防爆合格证-洛阳本安防爆认证代办-洛阳沪南抚防爆电气技术服务有限公司 | 喷砂机厂家_自动除锈抛丸机价格-成都泰盛吉自动化喷砂设备 | 隆众资讯-首页_大宗商品资讯_价格走势_市场行情| 高清视频编码器,4K音视频编解码器,直播编码器,流媒体服务器,深圳海威视讯技术有限公司 | 液压升降平台_剪叉式液压/导轨式升降机_传菜机定做「宁波日腾升降机厂家」 | 千淘酒店差旅平台-中国第一家针对TMC行业的酒店资源供应平台 | 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 硫化罐_蒸汽硫化罐_大型硫化罐-山东鑫泰鑫智能装备有限公司 | 能耗监测系统-节能监测系统-能源管理系统-三水智能化 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛婚外情取证-青岛王军侦探事务所 | 电子海图系统-电梯检验系统-智慧供热系统开发-商品房预售资金监管系统 | 吸音板,隔音板,吸音材料,吸音板价格,声学材料 - 佛山诺声吸音板厂家 | 首页 - 军军小站|张军博客| 干粉砂浆设备-干粉砂浆生产线-干混-石膏-保温砂浆设备生产线-腻子粉设备厂家-国恒机械 | 洗瓶机厂家-酒瓶玻璃瓶冲瓶机-瓶子烘干机-封口旋盖压盖打塞机_青州惠联灌装机械 | 舞台木地板厂家_体育运动木地板_室内篮球馆木地板_实木运动地板厂家_欧氏篮球地板推荐 | 导电银胶_LED封装导电银胶_半导体封装导电胶厂家-上海腾烁 | 网站建设,北京网站建设,北京网站建设公司,网站系统开发,北京网站制作公司,响应式网站,做网站公司,海淀做网站,朝阳做网站,昌平做网站,建站公司 | 南京种植牙医院【官方挂号】_南京治疗种植牙医院那个好_南京看种植牙哪里好_南京茀莱堡口腔医院 尼龙PA610树脂,尼龙PA612树脂,尼龙PA1010树脂,透明尼龙-谷骐科技【官网】 | 三佳互联一站式网站建设服务|网站开发|网站设计|网站搭建服务商 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 | 体检车_移动CT车_CT检查车_CT车_深圳市艾克瑞电气有限公司移动CT体检车厂家-深圳市艾克瑞电气有限公司 | 带式过滤机厂家_价格_型号规格参数-江西核威环保科技有限公司 | 赛尔特智能移动阳光房-阳光房厂家-赛尔特建筑科技(广东)有限公司 | 一技任务网_有一技之长,就来技术任务网|