qt(使用c++建立图形化界面)

发布于:2024-06-17 ⋅ 阅读:(20) ⋅ 点赞:(0)

建立QQ页面

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    //1:设置窗口标题
    this->setWindowTitle("QQ");
    //2:重新设计窗口大小
    this->resize(540,420);
    //3:设置窗口小图标 添加QIcon头文件 注意路径中替换/
    this->setWindowIcon(QIcon("C:/Users/Gerrard Yue/Desktop/pictur/pictrue/qq.png"));
    //4:设置窗口背景颜色
    this->setStyleSheet("background-color:rgb(255,255,255)");
    //5:固定窗口大小
    this->setFixedSize(540,420);
    //6:添加QPushButton头文件,创建按钮
    QPushButton *b1 = new QPushButton;
    //7:依赖窗口显示,显示父对象
    b1->setParent(this);
    //8:设置按钮背景颜色
    b1->setStyleSheet("background-color:rgb(12,193,254)");
    //9:设置按钮大小
    b1->resize(300,50);
    //10:移动合适位置
    b1->move(120,320);
    //11:设置文本
    b1->setText("登录");
    //12:创建自动登录小按钮b2
    QPushButton *b2 = new QPushButton(QIcon("C:/Users/Gerrard Yue/Desktop/pictur/1.png"),"自动登录",this);
    //13:设置按钮大小
    b2->resize(80,30);
    //14:移动合适位置
    b2->move(120,260);
    //15:创建自动登录小按钮b3
    QPushButton *b3 = new QPushButton(QIcon("C:/Users/Gerrard Yue/Desktop/pictur/1.png"),"记住密码",this);
    //16:设置按钮大小
    b3->resize(80,30);
    //17:移动合适位置
    b3->move(230,260);
    //18:创建自动登录小按钮b4
    QPushButton *b4 = new QPushButton("找回密码",this);
    //19:设置按钮大小
    b4->resize(80,30);
    //20:移动合适位置
    b4->move(340,260);
    //21:添加行编辑器QLineEdit头文件,创建第一个行编辑器
   // QLineEdit *e1 = new QLineEdit("手机号/QQ号",this);
    QLineEdit *e1 = new QLineEdit;
    //22:占位, 输入会覆盖“手机号 QQ”
    e1->setPlaceholderText("手机号/QQ号");
    //23:设置父对象
    e1->setParent(this);
    //24:设置大小
    e1->resize(300,30);
    //25:移动合适位置
    e1->move(120,170);

    //26:添加行编辑器QLineEdit头文件,创建第一个行编辑器
    QLineEdit *e2 = new QLineEdit;
    //27:占位, 输入会覆盖“手机号 QQ”
    e2->setPlaceholderText("密码");
    //28:设置父对象
    e2->setParent(this);
    //29:设置大小
    e2->resize(300,30);
    //30:移动合适位置
    e2->move(120,210);
    //31:设置密码显示设置输入模式
    e2->setEchoMode(QLineEdit::Password);



    //32:创建一个标签QLabel 添加头文件
    QLabel *l2 = new QLabel(this);
    //33:设置大小
    l2->resize(540,130);
    //34:移动
    l2->move(0,0);
    //35:设置动图对象接受动图,添加QMovie头文件
    QMovie *mv = new QMovie("C:/Users/Gerrard Yue/Desktop/pictur/pictrue/qq2.gif");
    //36:将动图设置到lab中
    l2->setMovie(mv);
    //37:让动图动起来
    mv->start();
    //38:让图片自适应大小
    l2->setScaledContents(true);

    //39:创建一个标签QLabel 添加头文件
    QLabel *l1 = new QLabel(this);
    //40:设置图片
    l1->setPixmap(QPixmap("C:/Users/Gerrard Yue/Desktop/pictur/pictrue/qq.png"));
    //41:设置大小
    l1->resize(130,130);
    //42:移动
    l1->move(200,20);



}

运行结果: