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

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

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

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

        PyQt5 和 Python 中的用戶輸入驗證

        User Input Validation in PyQt5 and Python(PyQt5 和 Python 中的用戶輸入驗證)

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

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

        <tfoot id='1vjQa'></tfoot>

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

                  本文介紹了PyQt5 和 Python 中的用戶輸入驗證的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  這是一個關(guān)于輸入驗證的兩部分問題,其中包含一個特定組件和另一個更通用的組件.

                  This is a two part question about input validation with one specific and another more general component.

                  具體:

                  在研究該主題時,我發(fā)現(xiàn) THIS on Regular表達(dá)式.我意識到這篇文章中的代碼使用的是 PyQt4.但是我想讓它與 PyQt5 一起工作,因為我已經(jīng)用它開始了我的項目.(顯然是盲目的——我只能找到它的 C++ 文檔)

                  While researching the topic, I found THIS on Regular Expressions. I realize that the code in this post is using PyQt4. However I wanted to get this working with PyQt5, since I had already started my project with it. (Obviously blindly - I can only find C++ documentation for it)

                  這是我嘗試過的:

                  # somewhere above:     
                  self.le_input = QtWidgets.QLineEdit()
                  
                  # at some point validate_input gets called:
                  # more on that in the second part of this question
                  
                  def validate_input(self):
                      reg_ex = QtCore.QRegExp(""[0-9]+.?[0-9]{,2}"")
                      input_validator = QtGui.QRegExpValidator(reg_ex, self.le_input.text())
                      self.le_input.setValidator(input_validator)
                  

                  當(dāng)我運行代碼時,出現(xiàn)以下錯誤:

                  When I run the code I get the following Error:

                  QRegExpValidator(parent: QObject = None): 參數(shù) 1 具有意外類型 'QRegExp'QRegExpValidator(QRegExp, parent: QObject = None): 參數(shù) 2 具有意外類型 'str'

                  QRegExpValidator(parent: QObject = None): argument 1 has unexpected type 'QRegExp' QRegExpValidator(QRegExp, parent: QObject = None): argument 2 has unexpected type 'str'

                  這些不正是需要的參數(shù)嗎?有誰知道如何讓這個工作?

                  Aren't these exactly the required arguments? Does anyone know how to get this working?

                  將軍:

                  在 Python 中使用 PyQt 實現(xiàn)實時驗證的有效方法是什么?

                  What is an effective way to implement live validation with PyQt in Python?

                  目前我會使用:

                  self.le_input.textChanged.connect(self.validate_input)
                  

                  這確實有效,但是一旦我嘗試將兩個相互影響的 QtLineEdits 連接到同一個插槽,事情就會停止工作,因為它們同時調(diào)用了textChanged".

                  This does work, but as soon as I try to connect two QtLineEdits, that affect each other, to the same slot, things stop working because "textChanged" gets called by both of them at the same time.

                  用例:兩個輸入字段:Amount before TAXAmount after TAX - 輸入時自動填充另一個字段.

                  Use case: Two input fields: Amount before TAX and Amount after TAX - and whichever you enter automatically fills the other one while typing.

                  先驗證,再計算,再輸出到其他字段.

                  First validation, then calculation, then output to the other field.

                  提前非常感謝!非常感謝任何幫助!

                  推薦答案

                  你可以為不同的QLineEdit對象設(shè)置不同的驗證器.

                  You can set different validators for different QLineEdit objects.

                  QRegExpValidator 有兩個構(gòu)造函數(shù):

                  QRegExpValidator(parent: QObject = None)
                  QRegExpValidator(QRegExp, parent: QObject = None)
                  

                  所以,您應(yīng)該將代碼更改為:

                  so, you should change your code to:

                  reg_ex = QRegExp("[0-9]+.?[0-9]{,2}")
                  input_validator = QRegExpValidator(reg_ex, self.le_input)
                  self.le_input.setValidator(input_validator)
                  

                  一旦為 QLineEdit 設(shè)置了驗證器,就不需要使用了

                  Once you set validator for QLineEdit, there is no need to use

                  self.le_input.textChanged.connect(self.validate_input)
                  

                  刪除即可.這應(yīng)該可以正常工作.

                  Just delete it. And that should work fine.

                  如果您想查找有關(guān) PyQt5 的文檔,您可以在控制臺中簡單地使用它:

                  If you want to find documentation about PyQt5, you can simple use this in your console:

                  pydoc3 PyQt5.QtGui.QRegExpValidator
                  

                  但是 pydoc 只能顯示很少的信息,所以你也應(yīng)該使用 C++ 版本的文檔.

                  But pydoc can only show you little information, so you should use C++ version documation as well.

                  最后,舉個例子:

                  from PyQt5.Qt import QApplication
                  from PyQt5.QtCore import QRegExp
                  from PyQt5.QtGui import QRegExpValidator
                  from PyQt5.QtWidgets import QWidget, QLineEdit
                  
                  import sys
                  
                  class MyWidget(QWidget):
                      def __init__(self, parent=None):
                          super(QWidget, self).__init__(parent)
                          self.le_input = QLineEdit(self)
                  
                          reg_ex = QRegExp("[0-9]+.?[0-9]{,2}")
                          input_validator = QRegExpValidator(reg_ex, self.le_input)
                          self.le_input.setValidator(input_validator)
                  
                  if __name__ == '__main__':
                      a = QApplication(sys.argv)
                  
                      w = MyWidget()
                      w.show()
                  
                      a.exec()
                  

                  這篇關(guān)于PyQt5 和 Python 中的用戶輸入驗證的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 啟動后進度躍升至 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時顯示進度條?)

                      <tfoot id='PzdQU'></tfoot>

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

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

                        <tbody id='PzdQU'></tbody>
                      • <bdo id='PzdQU'></bdo><ul id='PzdQU'></ul>

                        1. <legend id='PzdQU'><style id='PzdQU'><dir id='PzdQU'><q id='PzdQU'></q></dir></style></legend>
                          • 主站蜘蛛池模板: LZ-373测厚仪-华瑞VOC气体检测仪-个人有毒气体检测仪-厂家-深圳市深博瑞仪器仪表有限公司 | 顺辉瓷砖-大国品牌-中国顺辉| 小型高低温循环试验箱-可程式高低温湿热交变试验箱-东莞市拓德环境测试设备有限公司 | Win10系统下载_32位/64位系统/专业版/纯净版下载 | 广州食堂承包_广州团餐配送_广州堂食餐饮服务公司 - 旺记餐饮 | 奇酷教育-Python培训|UI培训|WEB大前端培训|Unity3D培训|HTML5培训|人工智能培训|JAVA开发的教育品牌 | 【MBA备考网】-2024年工商管理硕士MBA院校/报考条件/培训/考试科目/提前面试/考试/学费-MBA备考网 | 南京办公用品网-办公文具用品批发-打印机耗材采购 | 无线讲解器-导游讲解器-自助讲解器-分区讲解系统 品牌生产厂家[鹰米讲解-合肥市徽马信息科技有限公司] | 技德应用| 国产液相色谱仪-超高效液相色谱仪厂家-上海伍丰科学仪器有限公司 | 合肥白癜风医院_[治疗白癜风]哪家好_合肥北大白癜风医院 | 湖南自考_湖南自学考试网| 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 河北中仪伟创试验仪器有限公司是专业生产沥青,土工,水泥,混凝土等试验仪器的厂家,咨询电话:13373070969 | 馋嘴餐饮网_餐饮加盟店火爆好项目_餐饮连锁品牌加盟指南创业平台 | 隔离变压器-伺服变压器--输入输出电抗器-深圳市德而沃电气有限公司 | 专注氟塑料泵_衬氟泵_磁力泵_卧龙泵阀_化工泵专业品牌 - 梭川泵阀 | 带锯机|木工带锯机圆木推台锯|跑车带锯机|河北茂业机械制造有限公司| | 照相馆预约系统,微信公众号摄影门店系统,影楼管理软件-盟百网络 | 河南空气能热水器-洛阳空气能采暖-洛阳太阳能热水工程-洛阳润达高科空气能商行 | 土壤检测仪器_行星式球磨仪_土壤团粒分析仪厂家_山东莱恩德智能科技有限公司 | 广州监控安装公司_远程监控_安防弱电工程_无线wifi覆盖_泉威安防科技 | 事迹材料_个人事迹名人励志故事 学生作文网_中小学生作文大全与写作指导 | 压滤机滤板_厢式_隔膜_板框压滤机滤板厂家价格型号材质-大凯环保 | 厚壁钢管-厚壁无缝钢管-小口径厚壁钢管-大口径厚壁钢管 - 聊城宽达钢管有限公司 | 澳威全屋定制官网|极简衣柜十大品牌|衣柜加盟代理|全屋定制招商 百度爱采购运营研究社社群-店铺托管-爱采购代运营-良言多米网络公司 | 迪威娱乐|迪威娱乐客服|18183620002 | 机床主轴维修|刀塔维修|C轴维修-常州翔高精密机械有限公司 | 电缆接头_防水接头_电缆防水接头 - 乐清市新豪电气有限公司 | VOC检测仪-甲醛检测仪-气体报警器-气体检测仪厂家-深恒安科技有限公司 | 东莞韩创-专业绝缘骨架|马达塑胶零件|塑胶电机配件|塑封电机骨架厂家 | 中视电广_短视频拍摄_短视频推广_短视频代运营_宣传片拍摄_影视广告制作_中视电广 | 招商帮-一站式网络营销服务|搜索营销推广|信息流推广|短视视频营销推广|互联网整合营销|网络推广代运营|招商帮企业招商好帮手 | 临沂招聘网_人才市场_招聘信息_求职招聘找工作请认准【马头商标】 | 地图标注-手机导航电子地图如何标注-房地产商场地图标记【DiTuBiaoZhu.net】 | 恒湿机_除湿加湿一体机_恒湿净化消毒一体机厂家-杭州英腾电器有限公司 | DDoS安全防护官网-领先的DDoS安全防护服务商| 手机存放柜,超市储物柜,电子储物柜,自动寄存柜,行李寄存柜,自动存包柜,条码存包柜-上海天琪实业有限公司 | 恒压供水控制柜|无负压|一体化泵站控制柜|PLC远程调试|MCGS触摸屏|自动控制方案-联致自控设备 | 成都亚克力制品,PVC板,双色板雕刻加工,亚克力门牌,亚克力标牌,水晶字雕刻制作-零贰捌广告 |