头文件
#include<qpushbutton.h>
#include<qcheckbox.h>
#include<qlineedit.h>
#include<qdebug.h>
#include<qlabel.h>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
QPushButton *btn1;
QPushButton *del;
QCheckBox *btn3;
QCheckBox *btn4;
QLabel *lab3;
QLabel *lab2;
QLineEdit *edit1;
QLabel *lab1;
QLineEdit *edit2;
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
功能函数
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setFixedSize(560,380);
this->setWindowTitle("小沈聊天室");
this->setWindowIcon(QIcon("E:\\QT\\qt-pp\\icon_nhgbq8i4bf\\qq.png.jpg"));
//手动定义一个按钮
btn1=new QPushButton;
btn1->setParent(this);//将该界面设置为按钮的父组件
btn1->resize(100,30);
btn1->setText("登录");
btn1->move(200,250);
// btn1->setStyleSheet("background-color:red;"
// "borde-radius:10px;");
del=new QPushButton;
del->setParent(this);//将该界面设置为按钮的父组件
del->resize(100,30);
del->setText("取消");
del->move(300,250);
// QCheckBox *btn3=new QCheckBox("自动登录",this);
btn3=new QCheckBox;
btn3->setParent(this);
btn3->setText("自动登录");
btn3->resize(100,20);
btn3->move(300,300);
//QCheckBox *btn4=new QCheckBox("记住密码",this);
btn4=new QCheckBox;
btn4->setParent(this);
btn4->setText("记住密码");
btn4->resize(100,20);
btn4->move(190,300);
//插入一个图片
lab3=new QLabel;
lab3->setParent(this);
lab3->setScaledContents(true);
lab3->setPixmap(QPixmap("E:/QT/qt-pp/icon_nhgbq8i4bf/denglu.png"));
lab3->move(250,30);
lab3->resize(100,100);
//'账号'标
lab2=new QLabel;
lab2->setParent(this);
lab2->setScaledContents(true);
lab2->setPixmap(QPixmap("E:\\QT\\qt-pp\\icon_nhgbq8i4bf\\qq.png.jpg"));
lab2->move(170,150);
lab2->resize(30,20);
//账号输入框
edit1=new QLineEdit(this);
edit1->resize(200,30);
edit1->setPlaceholderText("账号");
edit1->move(200,150);
//‘密码’标签
lab1=new QLabel("密码",this);
lab1->move(170,200);
lab1->resize(30,20);
lab1->setScaledContents(true);
lab1->setPixmap(QPixmap("E:\\QT\\qt-pp\\icon_nhgbq8i4bf\\denglumima.png"));
//密码输入框
edit2=new QLineEdit(this);
edit2->resize(200,30);
edit2->setEchoMode(QLineEdit::Password);
edit2->setPlaceholderText("密码");
edit2->move(200,200);
}
MainWindow::~MainWindow()
{
delete ui;
}