1.手動實現(xiàn)登錄框;
---mychat.h---頭文件
#ifndef MYCHAT_H
#define MYCHAT_H
#include <QWidget>
#include <QDebug> //打印信息
#include <QIcon> //圖標(biāo)
#include <QPushButton> //按鈕
#include <QLineEdit> //行編輯器類
#include <QLabel> //標(biāo)簽類
class Mychat : public QWidget
{
Q_OBJECT
public:
Mychat(QWidget *parent = nullptr);
~Mychat();
QLabel *lab1; //標(biāo)簽類,設(shè)置背景
QLabel *lab2; //設(shè)置賬號圖標(biāo)
QLabel *lab3; //設(shè)置密碼圖標(biāo)
QLineEdit *edit1; //行編輯器類,設(shè)置明文賬號
QLineEdit *edit2; //設(shè)置密文密碼
QPushButton *but1; //按鈕類,設(shè)置登錄按鈕
QPushButton *but2; //設(shè)置取消按鈕
};
#endif // MYCHAT_H
---mychar.cpp---源文件
#include "mychat.h"
Mychat::Mychat(QWidget *parent)
: QWidget(parent)
{
//對組件界面的設(shè)置
qDebug()<<this->size();
this->setFixedSize(this->size()); //固定界面尺寸
this->setWindowOpacity(0.9); //透明度
//設(shè)置窗口
this->setWindowTitle(" 輕松一刻的你"); //窗口內(nèi)容
this->setWindowIcon(QIcon("D:\\桌面\\qt_icon\\企鵝.png")); //窗口圖標(biāo)
//設(shè)置背景
lab1 = new QLabel;
lab1->setParent(this); //將當(dāng)前組件設(shè)置為父組件
lab1->resize(700,200); //更改標(biāo)簽大小
lab1->setPixmap(QPixmap("D:\\桌面\\qt_icon\\背景1.jpg"));
lab1->setScaledContents(true); //自動適應(yīng)空間
//設(shè)置登錄頁面
//賬號密碼圖形標(biāo)簽
lab2 = new QLabel;
lab2->setParent(this); //將當(dāng)前組件設(shè)置為父組件
//lab2->setStyleSheet("background-color:blue;"); //參考
lab2->resize(50,40); //設(shè)置大小
lab2->move(170,250); //位置
lab2->setPixmap(QPixmap("D:\\桌面\\qt_icon\\賬號.png"));
lab2->setScaledContents(true); //自動適應(yīng)空間
lab3 = new QLabel(this);
//lab3->setStyleSheet("background-color:blue;"); //參考
lab3->resize(lab2->size()); //設(shè)置大小
lab3->move(170,320); //位置
lab3->setPixmap(QPixmap("D:\\桌面\\qt_icon\\密碼.png"));
lab3->setScaledContents(true); //自動適應(yīng)空間
//行文本
edit1 = new QLineEdit(this);
edit1->move(260,250); //位置
qDebug()<<edit1->size(); //獲取大小
edit1->resize(220,40); //設(shè)置大小
edit1->setPlaceholderText("賬號"); //占位提示
edit2 = new QLineEdit(this);
edit2->move(260,320); //位置
edit2->resize(edit1->size()); //設(shè)置大小
edit2->setEchoMode(QLineEdit::Password); //設(shè)置密文
edit2->setPlaceholderText("密碼"); //占位提示
//登錄,取消按鈕
but1 = new QPushButton(this);
qDebug()<<but1->size(); //獲取大小
//but1->setStyleSheet("background-color:red;"); //參考
but1->move(340,400); //位置
but1->resize(70,40); //設(shè)置大小
but1->setText("登錄"); //文本
but1->setIcon(QIcon("D:\\桌面\\qt_icon\\登錄.png"));
but2 = new QPushButton(this);
//but2->setStyleSheet("background-color:red;"); //參考
but2->move(440,400); //位置
but2->resize(but1->size()); //設(shè)置大小
but2->setText("取消"); //文本
but2->setIcon(QIcon("D:\\桌面\\qt_icon\\取消.png"));
}
Mychat::~Mychat()
{
}
---main.cpp---測試文件
#include "mychat.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Mychat w;
w.show();
return a.exec();
}
結(jié)果---
?文章來源地址http://www.zghlxwxcb.cn/news/detail-619761.html
2.今日思維導(dǎo)圖;
文章來源:http://www.zghlxwxcb.cn/news/detail-619761.html
?
到了這里,關(guān)于DAY1,Qt [ 手動實現(xiàn)登錄框(信息調(diào)試類,按鈕類,行編輯器類,標(biāo)簽類的使用)]的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!