PyQt5(10)QLineEdit控件与回显模式以及QFormLayout()表单布局的应用

'''

QLineEdit控件与回显模式

基本功能:输入单行的文本

EchoMode(回显模式)

4种回显模式

1. Normal正常输入什么显示什么
2. NoEcho敲半天什么都没有
3. Password变成点
4. PasswordEchoOnEdit显示一会变成*


Mac : Command    Windows:Control
'''
from PyQt5.QtWidgets import *
import sys

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

    def initUI(self):
        self.setWindowTitle('文本输入框的回显模式')

        formLayout = QFormLayout()#创建表单布局

        normalLineEdit = QLineEdit()
        noEchoLineEdit = QLineEdit()
        passwordLineEdit = QLineEdit()
        passwordEchoOnEditLineEdit = QLineEdit()

        formLayout.addRow("Normal",normalLineEdit)#前面是文本框的名字
        formLayout.addRow("NoEcho", noEchoLineEdit)#把控件添加到布局上,不同的布局添加方式不同
        formLayout.addRow("Password",passwordLineEdit)
        formLayout.addRow("PasswordEchoOnEdit",passwordEchoOnEditLineEdit)

        # placeholdertext

        normalLineEdit.setPlaceholderText("Normal")#设置提示信息,框内
        noEchoLineEdit.setPlaceholderText("NoEcho")
        passwordLineEdit.setPlaceholderText("Password")
        passwordEchoOnEditLineEdit.setPlaceholderText("PasswordEchoOnEdit")

        normalLineEdit.setEchoMode(QLineEdit.Normal)
        noEchoLineEdit.setEchoMode(QLineEdit.NoEcho)
        passwordLineEdit.setEchoMode(QLineEdit.Password)
        passwordEchoOnEditLineEdit.setEchoMode(QLineEdit.PasswordEchoOnEdit)

        self.setLayout(formLayout)

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

 

posted on 2020-02-23 12:40  把恐惧变成希望  阅读(371)  评论(0)    收藏  举报

导航