Qt 的界面设计,初学者

m0_37163532 2017-01-02 11:01:58
就是比如一个注册界面,我想在用户填写符合帐号,密码,邮箱等等格式正确后,让注册按钮变色,我怎么能把这些输入正确的信号你在一起啊?由于之前的lineEdit中为了 判断输入格式正确,已经有了对应的槽。
#include "dialog.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QFile>
#include <QDebug>
#include <QPixmap>
#include <QMessageBox>
#include <QMouseEvent>
#include <QRegExp>
#include <QRegExpValidator>
#include "mylineedit.h"


const static QString gSuccess = ":/imgs/success.png";
const static QString gFailed = ":/imgs/failed.png";

Dialog::Dialog(QWidget *parent)
: QDialog(parent)

{

this->setFixedSize(350,450);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setObjectName("mainFrame");

////////////////logo + title///////////
nLogoLabel =new QLabel;
nLogoLabel->setFixedSize(34,48);
nLogoLabel->setObjectName("logo");
//<<<<<<< .mine
// nLogoLabel->setStyleSheet("QLabel{image:url(:/imgs/logo.png);}");

//||||||| .r126
// nLogoLabel->setStyleSheet("QLabel{image:url(:/imgs/logo.png);}");

//=======
//>>>>>>> .r127
nTitleLabel = new QLabel(QStringLiteral("通行证注册"));
nTitleLabel->setFixedHeight(80);
nTitleLabel->setObjectName("title");
QHBoxLayout* nTopLayout = new QHBoxLayout;
nTopLayout->setAlignment(Qt::AlignCenter);
nTopLayout->setSpacing(10);
nTopLayout->addWidget(nLogoLabel);
nTopLayout->addWidget(nTitleLabel);

///////////////////////////////////////////////////////////////////
nAccountLineEdit = new MyLineEdit;
connect(nAccountLineEdit,SIGNAL(editingFinished()), this,SLOT(slotAccount()));

nPasswordLineEdit = new MyLineEdit;
nPasswordLineEdit->setEchoMode(QLineEdit::Password);

nConfirmPasswordLineEdit= new MyLineEdit;
nConfirmPasswordLineEdit->setEchoMode(QLineEdit::Password);

nEmailAddressLineEdit= new MyLineEdit;
nEmailAddressLineEdit->setPlaceholderText(QStringLiteral("请正确输入你的邮箱地址"));
connect(nEmailAddressLineEdit,SIGNAL(editingFinished()), this,SLOT(slotEmail()));



nTelephoneNumberLineEdit= new MyLineEdit;
nTelephoneNumberLineEdit->setPlaceholderText(QStringLiteral("正确填写手机号码"));
connect(nTelephoneNumberLineEdit,SIGNAL(editingFinished()), this,SLOT(slotNumber()));

QFormLayout * centerFormLayout = new QFormLayout;
centerFormLayout->setFormAlignment(Qt::AlignCenter);
centerFormLayout->setHorizontalSpacing(12);
centerFormLayout->setVerticalSpacing(16);
centerFormLayout->setLabelAlignment(Qt::AlignVCenter | Qt::AlignRight);
centerFormLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);

centerFormLayout->addRow(QStringLiteral("账号"),nAccountLineEdit);
centerFormLayout->addRow(QStringLiteral("密码"),nPasswordLineEdit);
centerFormLayout->addRow(QStringLiteral("确认密码"),nConfirmPasswordLineEdit);
centerFormLayout->addRow(QStringLiteral("邮箱地址"),nEmailAddressLineEdit);
centerFormLayout->addRow(QStringLiteral("手机号码"),nTelephoneNumberLineEdit);
for(int i = 0; i < centerFormLayout->rowCount();++i){
centerFormLayout->itemAt(i,QFormLayout::LabelRole)->widget()->setFixedHeight(33);
}

nReadedCheckBox = new QCheckBox;
nReadedLabel = new QLabel(QStringLiteral("我已阅读并接受<font color='#1562d6'>版权声明隐私保护</font>条款"));
QHBoxLayout * footLayout = new QHBoxLayout;
footLayout->addWidget(nReadedCheckBox);
footLayout->addWidget(nReadedLabel);

nRegisterPushButton= new QPushButton(QStringLiteral("马上注册"));
nRegisterPushButton->setFixedSize(202,33);
nRegisterPushButton->setObjectName("register");


//connect(this,SIGNAL(signalsTest(bool)), this,SLOT(slotRegister()));


centerFormLayout->addItem(footLayout);//增加列表项
centerFormLayout->addWidget(nRegisterPushButton);

nFrameCenter = new QFrame;
nFrameCenter->setLayout(centerFormLayout);
nFrameCenter->setObjectName("frameCenter");
nFrameCenter->setFixedHeight(324);//

QVBoxLayout* vBoxLayoutmain = new QVBoxLayout;
vBoxLayoutmain->setContentsMargins(5,0,5,46);
vBoxLayoutmain->setAlignment(Qt::AlignCenter);
vBoxLayoutmain->addLayout(nTopLayout);
vBoxLayoutmain->addWidget(nFrameCenter);
setLayout(vBoxLayoutmain);


、、、、、、、、、、、、

QFile file(":/login.css");
bool isOpen = file.open(QIODevice::ReadOnly);
if(isOpen == false){
qDebug() << "open file failed:" << file.errorString();
return;
}
QString styleSheet = file.readAll();
setStyleSheet(styleSheet);
}

Dialog::~Dialog()
{
}

void Dialog::slotTest()
{

nRegisterPushButton->setStyleSheet("QPushButton{background-color:blue}");
}

void Dialog::slotAccount(){
nAccountLineEdit->showIcon(nAccountLineEdit->text()=="111111"?gSuccess:gFailed);

}


void Dialog::slotEmail()
{
// QRegExp regExp("^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$");//创建了一个模式
// QRegExpValidator pattern(regExp,this);//创建了一个表达式
// nEmailAddressLineEdit->setValidator(&pattern);//交付使用

QString input = nEmailAddressLineEdit->text();
if(QRegExp(tr("^[\\w\\a]+@[\\w\\d]+[\.a-z]+$")).exactMatch(input)){
nEmailAddressLineEdit->showIcon(gSuccess);
emit signalsTest(nEmailAddressLineEdit);

connect(nEmailAddressLineEdit,SIGNAL(signalsTest()), this,SLOT(slotTest()));

}else{
nEmailAddressLineEdit->showIcon(gFailed);
}

}
void Dialog::slotNumber(){
QString input = nTelephoneNumberLineEdit->text();
if(QRegExp(tr("^1[\\d]{10}")).exactMatch(input)){
nTelephoneNumberLineEdit->showIcon(gSuccess);
emit signalsTest(nTelephoneNumberLineEdit);

}else{
nTelephoneNumberLineEdit->showIcon(gFailed);
}
}

void Dialog::slotRegister(){

// nRegisterPushButton->setStyleSheet("QPushButton{background-color:blue}");
}

void Dialog::mousePressEvent(QMouseEvent *event){
relativePos = event->globalPos();
mMoving = true;
}

void Dialog::mouseMoveEvent(QMouseEvent *event){
if(mMoving){
this->move(pos()+(event->globalPos() - relativePos));
relativePos = event->globalPos();
}
}

void Dialog::mouseReleaseEvent(QMouseEvent *event){
mMoving=false;
}

//abc@chinabigdata.com
...全文
314 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
小灸舞 2017-01-04
  • 打赏
  • 举报
回复
connect一下lineEdit的textChanged(QString)信号?
每次输入有变化就判断一下格式是不是正确了,如果正确了就注册按钮变绿

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧