QT day1

文章展示了如何使用Qt库创建一个简单的GUI登录界面,包括设置按钮、复选框、标签和文本编辑框,以及界面布局和图像显示。
摘要由CSDN通过智能技术生成

 头文件

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值