QQ登录界面的实现
代码展示
wight.h
# ifndef WIDGET_H
# define WIDGET_H
# include <QWidget>
# include <QLineEdit>
# include <QPushButton>
# include <QVBoxLayout>
# include <QRadioButton>
# include <QIcon>
# include <QLabel>
# include <QDebug>
# include <QPixmap>
# include <QPainter>
class Widget : public QWidget
{
Q_OBJECT
public :
Widget ( QWidget * parent = nullptr ) ;
~ Widget ( ) ;
} ;
# endif
wight.cpp
# include "widget.h"
Widget :: Widget ( QWidget * parent)
: QWidget ( parent)
{
setWindowTitle ( "QQ 登录" ) ;
this -> setFixedSize ( 480 , 672 ) ;
this -> setStyleSheet ( "background-color:#271938" ) ;
QLabel * iconLabel = new QLabel ( this ) ;
iconLabel-> resize ( 120 , 120 ) ;
iconLabel-> setPixmap ( QPixmap ( "C:/Users/者行孙/Desktop/Icon/01.png" ) ) ;
iconLabel-> setScaledContents ( true ) ;
iconLabel-> move ( 178 , 100 ) ;
QLineEdit * edit1 = new QLineEdit ( this ) ;
edit1-> resize ( 384 , 64 ) ;
edit1-> setStyleSheet ( "background-color:#37335b;color:#a8a2ae;font-size:25px;border-radius:10px" ) ;
edit1-> setAlignment ( Qt:: AlignCenter) ;
edit1-> setPlaceholderText ( "手机号/QQ号/邮箱" ) ;
edit1-> move ( 48 , 251 ) ;
QLineEdit * edit2 = new QLineEdit ( this ) ;
edit2-> resize ( 384 , 64 ) ;
edit2-> setStyleSheet ( "background-color:#37335b;color:#a8a2ae;font-size:25px;border-radius:10px" ) ;
edit2-> setAlignment ( Qt:: AlignCenter) ;
edit2-> setEchoMode ( QLineEdit:: Password) ;
edit2-> setPlaceholderText ( "请输入QQ密码" ) ;
edit2-> move ( 48 , edit1-> y ( ) + 85 ) ;
QRadioButton * circleRadioButton = new QRadioButton ( this ) ;
circleRadioButton-> setText ( "已阅读并同意服务协议和QQ隐私保护指引" ) ;
circleRadioButton-> setStyleSheet ( "color: #868285; font-size: 18px;" ) ;
circleRadioButton-> move ( 48 , edit2-> y ( ) + 85 ) ;
circleRadioButton-> setChecked ( false ) ;
QPushButton * loginButton = new QPushButton ( "登录" , this ) ;
loginButton-> setStyleSheet ( "background-color: #23335a;color:#685e75;font-size: 22px; border-radius: 10px;" ) ;
loginButton-> resize ( 385 , 57 ) ;
loginButton-> move ( 48 , circleRadioButton-> y ( ) + 40 ) ;
QLabel * linkLabel = new QLabel ( this ) ;
linkLabel-> setText ( "扫码登录 | 更多选项" ) ;
linkLabel-> setOpenExternalLinks ( true ) ;
linkLabel-> setStyleSheet ( "color: #2c71da; font-size: 20px;" ) ;
linkLabel-> move ( 141 , loginButton-> y ( ) + 120 ) ;
}
Widget :: ~ Widget ( )
{
}
main.c
# include "widget.h"
# include <QApplication>
int main ( int argc, char * argv[ ] )
{
QApplication a ( argc, argv) ;
Widget w;
w. show ( ) ;
return a. exec ( ) ;
}
运行结果
原始代码注释
mywindow.h
# ifndef MYWINDOW_H
# define MYWINDOW_H
# include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui { class MyWindow ; }
QT_END_NAMESPACE
class MyWindow : public QWidget
{
Q_OBJECT
public :
MyWindow ( QWidget * parent = nullptr ) ;
~ MyWindow ( ) ;
private :
Ui:: MyWindow * ui;
} ;
# endif
mywindow.cpp
# include "mywindow.h"
# include "ui_mywindow.h"
MyWindow :: MyWindow ( QWidget * parent)
: QWidget ( parent)
, ui ( new Ui:: MyWindow)
{
ui-> setupUi ( this ) ;
}
MyWindow :: ~ MyWindow ( )
{
delete ui;
}
main.cpp
# include "mywindow.h"
# include <QApplication>
int main ( int argc, char * argv[ ] )
{
QApplication a ( argc, argv) ;
MyWindow w;
w. show ( ) ;
return a. exec ( ) ;
}
思维导图