widget.cpp
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
QPushButton *btn1 =new QPushButton("登录",this);
this->setFixedSize(640,480);
btn1->resize(80,40);
btn1->move(200,300);
btn1->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\中国结\\picture"));
btn1->setStyleSheet("color :white; background-color:skyblue;border-radius:10px");
QPushButton *btn2 =new QPushButton("取消",this);
btn2->resize(btn1->size());
btn2->move(btn1->x()+btn1->width()+50,btn1->y());
btn2->setIcon(QIcon("C:\\Users\\Administrator\\Desktop\\中国结\\picture"));
btn2->setStyleSheet("color :white; background-color:skyblue;border-radius:10px");
QLineEdit *edit1=new QLineEdit(this);
edit1->resize(300,30);
edit1->move(180,220);
edit1->setStyleSheet("color :black;");
edit1->setAlignment(Qt::AlignCenter);
edit1->setEchoMode(QLineEdit::Password);
edit1->setPlaceholderText("输入QQ密码");
QLineEdit *edit2=new QLineEdit(this);
edit2->resize(300,30);
edit2->move(edit1->x(),edit1->y()-edit1->height()-10);
edit2->setStyleSheet("color :black;");
edit2->setAlignment(Qt::AlignCenter);
edit2->setPlaceholderText("输入QQ账号");
QLabel *lab1 = new QLabel;
lab1->setParent(this);
lab1->setText("密码:");
lab1->move(edit1->x()-40, edit1->y()+10);
QLabel *lab2 = new QLabel;
lab2->setParent(this);
lab2->setText("账号:");
lab2->move(edit1->x()-40, edit1->y()-30);
}
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();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QPushButton>
#include<QLineEdit>
#include<QLabel>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
};
#endif // WIDGET_H