自己走过不少弯路,这个当做是给后来者学习的一个示例吧,少走点弯路。
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. |