1.设置一个用户界面
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
//窗口
this->setFixedSize(550,650); //锁定窗口大小
this->setWindowTitle("Devil May Cry 5"); //窗口标题
this->setWindowIcon(QIcon("C:\\Users\\20723\\Pictures\\Saved Pictures\\th (1).jpg")); //窗口图标
//LOGL
QLabel *lab3 = new QLabel(this); //定义标签,依附在界面上
lab3->resize(550,340);
lab3->setPixmap(QPixmap("C:\\Users\\20723\\Pictures\\Saved Pictures\\OIP-C.jpg")); //标签图标
lab3->setScaledContents(true); //图标自适应
//LOGL
QLabel *lab4 = new QLabel(this); //定义标签,依附在界面上
lab4->resize(550,310);
lab4->setPixmap(QPixmap("C:\\Users\\20723\\Pictures\\Saved Pictures\\OIP-C (1).jpg")); //标签图标
lab4->setScaledContents(true); //图标自适应
lab4->move(0,340);
//登录按钮
QPushButton *btn1 = new QPushButton("登录", this); //定义“登录”按钮,依附在界面上
btn1->setIcon(QIcon("C:\\Users\\20723\\Pictures\\Saved Pictures\\icon\\login.png")); //按钮图标
btn1->resize(120,50);
btn1->move(160,320);
//取消按钮
QPushButton *btn2 = new QPushButton("取消", this); //定义“取消”按钮,依附在界面上
btn2->setIcon(QIcon("C:\\Users\\20723\\Pictures\\Saved Pictures\\icon\\cancel.png")); //按钮图标
btn2->resize(120,50);
btn2->move(btn1->x()+140,btn1->y());
//账户图标
QLabel *lab1 = new QLabel(this); //定义标签,依附在界面上
lab1->resize(50,40);
lab1->move(120,180);
lab1->setPixmap(QPixmap("C:\\Users\\20723\\Pictures\\Saved Pictures\\icon\\userName.jpg")); //标签图标
lab1->setScaledContents(true); //图标自适应
//密码图标
QLabel *lab2 = new QLabel(this); //定义标签,依附在界面上
lab2->resize(50,40);
lab2->move(lab1->x(),lab1->y()+75);
lab2->setPixmap(QPixmap("C:\\Users\\20723\\Pictures\\Saved Pictures\\icon\\passwd.jpg")); //标签图标
lab2->setScaledContents(true); //图标自适应
//账户行
QLineEdit *edit1 = new QLineEdit(this); //定义行编辑器,依附在界面上
edit1->setPlaceholderText("if you want it");
edit1->resize(240,40);
edit1->move(lab1->x()+65,lab1->y());
//密码行
QLineEdit *edit2 = new QLineEdit(this); //定义行编辑器,依附在界面上
edit2->setPlaceholderText("then you'll have to take it");
edit2->resize(240,40);
edit2->move(lab2->x()+65,lab2->y());
edit2->setEchoMode(QLineEdit::Password); //设置密码回显模式
}
Widget::~Widget()
{
}
思维导图: