您的位置:首页 > 运维架构 > Linux

QT5-控件-QLineEdit-文本输入控件,用来输入密码什么的还不错,可以和Linux登录一样不移动光标哦

2016-02-22 20:39 666 查看
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QLineEdit>
#include <QLabel>

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();

QLineEdit* edit[10];
QLabel* label ;
public slots:
void textChanged(const QString& text);
};

#endif // MAINWINDOW_H


#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->resize(400,400);
this->centralWidget();

int ypos = 30 ;
for(int i=0;i<5;i++)
{
edit[i] = new QLineEdit("世界,不好",this);
edit[i]->setGeometry(10,ypos,200,40);
ypos += 50 ;
}
// 设置显示模式
edit[1]->setEchoMode(QLineEdit::Normal); // 与默认类型一致
edit[2]->setEchoMode(QLineEdit::NoEcho); // 隐藏输入文本,不改变光标位置
edit[3]->setEchoMode(QLineEdit::Password); // 用*表示文本
edit[4]->setEchoMode(QLineEdit::PasswordEchoOnEdit); // 若编辑文本与默认相同,失去焦点显示*

label = new QLabel("文本框内容为:",this);
label->setGeometry(10,300,350,30);
connect(edit[0],SIGNAL(textChanged(QString)),this,SLOT(textChanged(QString)));

}

MainWindow::~MainWindow()
{

}

void MainWindow::textChanged(const QString& text)
{
label->setText("文本框内容为:"+text);
}


#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: