PyQt5-QLineEdit综合案例

# encoding: utf-8
'''===================================================
@Project -> File : qt5003 -> QLineEditDemo.py
@IDE             : qt5003
@Author          : Mr. Batac
@Date            : 2020-03-18 21:45
@Desc            :
======================================================'''

from PyQt5.QtWidgets import *
from PyQt5.QtGui import  *
from PyQt5.QtCore import Qt
import sys

class QLineEditDemo(QWidget):
    def __init__(self):
        super(QLineEditDemo, self).__init__()
        self.initUI()

    def initUI(self):
        edit1 = QLineEdit()

        #使用int校验器
        edit1.setValidator(QIntValidator())
        edit1.setMaxLength(4) # 不超过9999
        edit1.setAlignment(Qt.AlignRight)
        edit1.setFont(QFont('Arial', 20))

        edit2 = QLineEdit()
        edit2.setValidator(QDoubleValidator(0.99, 99.99, 2))

        edit3 = QLineEdit()
        edit3.setInputMask('99_9999_999999;#')


        edit4 = QLineEdit()
        edit4.textChanged.connect(self.textChange)

        edit5 = QLineEdit()
        edit5.setEchoMode(QLineEdit.Password)
        edit5.editingFinished.connect(self.enterPress)

        edit6 = QLineEdit("Hello PyQt5")
        edit6.setReadOnly(True)


        formLayout = QFormLayout(self)
        formLayout.addRow("整数校验", edit1)
        formLayout.addRow("浮点校验", edit2)
        formLayout.addRow("掩码", edit3)
        formLayout.addRow("文本变化", edit4)
        formLayout.addRow("文本回显模式", edit5)
        formLayout.addRow("只能读取", edit6)


        self.setWindowTitle("QlineEdit综合案例")

    def textChange(self, text):
        print("文字内容变化:"+text)


    def enterPress(self):
        print("结束了")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    mainView = QLineEditDemo()
    mainView.show()
    sys.exit(app.exec_())

发布了124 篇原创文章 · 获赞 11 · 访问量 4万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览