zoukankan      html  css  js  c++  java
  • 一个基于QT简单登录对话框

    1. 登录对话框式样

    2. QLoginDialog.h

    #ifndef DIALOG_H
    #define DIALOG_H
    
    #include <QtGui/QDialog>
    #include <QPushButton>
    #include <QLabel>
    #include <QLineEdit>
    
    class QLoginDialog : public QDialog
    {
        Q_OBJECT
    private:
        QLabel UserLable;
        QLabel PwdLable;
        QPushButton CancelBtn;
        QPushButton LoginBtn;
        QLineEdit UserLineEdit;
        QLineEdit PwdLineEdit;
        QString m_user;
        QString m_pwd;
    private slots:
        void CancelBtn_Clicked();
        void LoginBtn_Clicked();
    public:
        QLoginDialog(QWidget *parent = 0);
        QString GetUser();
        QString GetPwd();
        ~QLoginDialog();
    };
    
    #endif // DIALOG_H

    3. QLoginDialog.cpp

    #include <QDebug>
    #include "QLoginDialog.h"
    
    QLoginDialog::QLoginDialog(QWidget *parent) : QDialog(parent, Qt::WindowCloseButtonHint),
        UserLable(this), PwdLable(this), CancelBtn(this), LoginBtn(this),UserLineEdit(this), PwdLineEdit(this)
    {
        UserLable.setText("User Name");
        UserLable.move(20, 30);
        UserLable.resize(60, 25);
    
        UserLineEdit.move(85, 30);
        UserLineEdit.resize(180, 25);
    
        PwdLable.setText("Password");
        PwdLable.move(20, 65);
        PwdLable.resize(60, 25);
    
        PwdLineEdit.move(85, 65);
        PwdLineEdit.resize(180, 25);
        PwdLineEdit.setEchoMode(QLineEdit::Password);
    
        CancelBtn.setText("Cancel");
        CancelBtn.move(85, 110);
        CancelBtn.resize(85, 30);
    
        LoginBtn.setText("Login");
        LoginBtn.move(180, 110);
        LoginBtn.resize(85, 30);
    
        setWindowTitle("Login");
        setFixedSize(290, 170);
    
        connect(&CancelBtn, SIGNAL(clicked()), this, SLOT(CancelBtn_Clicked()));
        connect(&LoginBtn, SIGNAL(clicked()), this, SLOT(LoginBtn_Clicked()));
    
    }
    void QLoginDialog::CancelBtn_Clicked() { qDebug("CancelBtn_Clicked start"); done(Rejected); qDebug("CancelBtn_Clicked end"); }
    void QLoginDialog::LoginBtn_Clicked() { qDebug("LoginBtn_Clicked start"); m_user = UserLineEdit.text().trimmed();//trimmed():Delete space m_pwd = PwdLineEdit.text(); done(Accepted); qDebug("LoginBtn_Clicked end"); } QString QLoginDialog::GetUser() { return m_user; }
    QString QLoginDialog::GetPwd() {
    return m_pwd; } QLoginDialog::~QLoginDialog() { }
  • 相关阅读:
    java基础学习总结——GUI编程(二)
    003_Java笔记3:Eclipse添加jar包
    001_Eclipse编写第一个Java程序
    002_JavaSE笔记:单例模式
    001_IntelliJ IDEA详细安装步骤
    T4批量生成多文件
    T4模版引擎之基础入门
    T4模版引擎之生成数据库实体类
    localForage——轻松实现 Web 离线存储
    visual studio code插件精选
  • 原文地址:https://www.cnblogs.com/wulei0630/p/6690482.html
Copyright © 2011-2022 走看看