qt LineEdit常用的函数

本文分享了QLineEdit的设置技巧,包括密码输入模式、验证器、样式定制等,旨在帮助读者减少在输入框组件上的开发弯路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

自己走过不少弯路,这个当做是给后来者学习的一个示例吧,少走点弯路。

    QLineEdit  * lineEdit  =  new QLineEdit(this);
    lineEdit->setText("Hi,QLineEdit!");//设置文字
    lineEdit->text();//获取输入框的文字
    lineEdit->setEchoMode(QLineEdit::Password);//设置密码输入模式,显示是小圆点,看不到明文
    lineEdit->setObjectName(QString("lineEdit"));//设置名称
    lineEdit->installEventFilter(this);//安装过滤事件
    lineEdit->setReadOnly(true);//设置只读属性
    lineEdit->setFocus();//设置焦点
    lineEdit->setVisible(false);//设置不可视
    lineEdit->setEnabled(false);//设置不可以用,不可以编辑,不可读,不可聚焦,只能看到
    lineEdit->clear();//清除输入框文本
    QIntValidator *intValidator = new QIntValidator(-255,255,this);
    lineEdit->setValidator(intValidator);//设置输入范围为-255到255
    lineEdit->setPlaceholderText("请输入-255-255之间的数");//设置背景提示
    int width   =  lineEdit->width();//获取宽度
    int height  =  lineEdit->height();//获取高度
    int x       =  lineEdit->x();//获取横坐标值
    int y       =  lineEdit->y();//获取纵坐标值
    lineEdit->setGeometry(x,y,width,height);//设置位置
    lineEdit->setStyleSheet("QLineEdit{\
                                color: #ffffff;\
                                border: 2px solid rgba(255,255,255,0);\
                                border-radius: 3px;\
                                background-color: rgba(0,0,0,0);\
                                padding-left: 5px;\
                            }");//设置样式

 

QLineEdit::Normal

0

Display characters as they are entered. This is the default.

QLineEdit::NoEcho

1

Do not display anything. This may be appropriate for passwords where even the length of the password should be kept secret.

QLineEdit::Password

2

Display platform-dependent password mask characters instead of the characters actually entered.

QLineEdit::PasswordEchoOnEdit

3

Display characters as they are entered while editing otherwise display characters as with Password.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值