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() { }
  • 相关阅读:
    ansj分词原理
    于erlang依赖的linux调优
    Gearman
    生成具有三态背景图片的按钮
    tracert
    Wings 3D
    jira
    Erlang编程语言的一些痛点
    QTreeView 限制特定的深度、特定深度下的列 是否可以编辑
    QStandardItemModel角色控制及QTreeView添加不同的右键菜单
  • 原文地址:https://www.cnblogs.com/wulei0630/p/6690482.html
Copyright © 2011-2022 走看看