QT————qq登录界面

我们要先写一个小dialog这个登录界面,登录成功之后才显示QQ主界面
MyQDialog.h继承Dialog

#ifndef MYQDIALOG_H
#define MYQDIALOG_H

#include <QLineEdit>
#include <QCheckBox>
#include <QPushButton>
#include <QRadioButton>
#include <QLabel>


#include <QDialog>

class MyQDialog : public QDialog
{
    Q_OBJECT

public:
    MyQDialog();

public slots:

    void setpass(bool flag){

      if(!flag)
             LineEdit1->setEchoMode(QLineEdit::Password);
       else
             LineEdit1->setEchoMode(QLineEdit::Normal);
    }

public slots:

    void loading_push(){
        stat = true;
        close();
    }

public:

    static int getstat(){

        MyQDialog  da;
        da.setFixedSize(600,400);
        da.exec();

        return da.stat;

    }

private:
        int stat;
        QLineEdit *LineEdit0,*LineEdit1;
        QCheckBox *CheckBox;
        QPushButton *PushButton;
        QRadioButton *RadioButton;
        QLabel *Label0,*Label1;


};

#endif // MYQDIALOG_H

实现dialog.
myqdialog.h


```cpp
#include "myqdialog.h"


#include <QVBoxLayout>
#include <QHBoxLayout>

MyQDialog::MyQDialog()
{
       Label0 = new QLabel("welcome useing my QQ");
       Label1 = new QLabel;
       QPixmap pix("1.png");
       Label1->setFixedSize(200,250);
       Label1->setScaledContents(true);
       Label1->setPixmap(pix);

       QVBoxLayout *vbox0 = new QVBoxLayout;
       vbox0->addWidget(Label1);
       vbox0->addWidget(Label0);


       LineEdit0 = new QLineEdit;
       LineEdit0->setFixedSize(300,50);
       LineEdit1 = new QLineEdit;
       LineEdit1->setFixedSize(300,50);
       LineEdit1->setEchoMode(QLineEdit::Password);
       CheckBox = new QCheckBox("show password");
       PushButton = new QPushButton("Lading");
       PushButton->setFixedSize(200,50);
       RadioButton = new QRadioButton("I accept this!");
       QVBoxLayout *vbox1 = new QVBoxLayout;
       vbox1->addWidget(LineEdit0);
       vbox1->addWidget(LineEdit1);
       vbox1->addWidget(CheckBox);
       vbox1->addWidget(RadioButton);
       vbox1->addWidget(PushButton);

       QHBoxLayout *hbox = new QHBoxLayout;

       hbox->addLayout(vbox0);
       hbox->addLayout(vbox1);


       this->setLayout(hbox);

       connect(CheckBox,SIGNAL(clicked(bool)),this ,SLOT(setpass(bool)));

       stat = false;

       connect(PushButton,SIGNAL(clicked(bool)),this ,SLOT(loading_push()));



}

接下来就是要实现登录成功才显示主界面
widget.h

ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

#include <QTabWidget>
#include <QToolBox>
#include <QLabel>
#include <QPushButton>

class Widget : public QWidget
{
    Q_OBJECT

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



private:
    QLabel *Label0,*Label1;
    QToolBox *ToolBox0,*ToolBox1,*ToolBox2;
   // QTabWidget *TabWidget0,*TabWidget1,*TabWidget2;
    QPushButton *pb0,*pb1,*pb2,*pb3,*pb4,*pb5,*pb6,*pb7;


};

#endif // WIDGET_H

```cpp
widget.cpp
#include "widget.h"
#include <QDialog>

#include "myqdialog.h"

#include <QVBoxLayout>
#include <QHBoxLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
  int stat = MyQDialog::getstat();
  if(!stat)
            exit(0);

  Label0 = new QLabel;
  QPixmap pix("2.png");
  Label0->setFixedSize(150,150);
  Label0->setScaledContents(true);
  Label0->setPixmap(pix);
  QHBoxLayout *Hbox = new QHBoxLayout;
  Hbox->addWidget(Label0);


  Label1 = new QLabel("lineing");
  Hbox->addWidget(Label0);


  ToolBox0 = new QToolBox;
  ToolBox1 = new QToolBox;
  ToolBox2 = new QToolBox;
  pb0 = new QPushButton("wzfdashuaibi");
  pb1 = new QPushButton("好友2");
  pb2 = new QPushButton("好友3");
  pb3 = new QPushButton("好友4");
  pb4 = new QPushButton("好友5");
  pb5 = new QPushButton("好友6");
  pb6 = new QPushButton("好友7");
  pb7 = new QPushButton("好友8");

  ToolBox0->addItem(pb0,"groap1");


  ToolBox1->addItem(pb1,"groap1");
  ToolBox1->addItem(pb2,"groap1");
  ToolBox1->addItem(pb3,"groap2");
  ToolBox1->addItem(pb4,"groap2");

  ToolBox2->addItem(pb5,"groap2");
  ToolBox2->addItem(pb6,"groap3");
  ToolBox2->addItem(pb7,"groap3");

  QVBoxLayout *vbox = new QVBoxLayout;
  vbox->addWidget(ToolBox0);
  vbox->addWidget(ToolBox1);
  vbox->addWidget(ToolBox2);

  QVBoxLayout *mainvbox = new QVBoxLayout;
  mainvbox->addLayout(Hbox);
  mainvbox->addLayout(vbox);

  this->setLayout(mainvbox);







}

Widget::~Widget()
{

}

main()

```cpp
#include "widget.h"
#include <QApplication>

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

    return a.exec();
}```

效果:
在这里插入图片描述
在这里插入图片描述
点击登录就会出现
在这里插入图片描述
这里没有添加数据库等,也没有注册模块。
还可以再写一个dialog,当你点击一个好友的pushbutton的时候,就会弹出聊天窗口窗口
在这个聊天窗口,可以编辑,文字字体,颜色,。。。。
时间关系,下次来写。
这个界面丑是丑了点但是还是可以用的

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值