一、学习的知识点
qt的安装
安装路径尽量不改,或者只修改盘符
https://www.jb51.net/article/186984.htm
qt项目
项目创建
- 创建的路径不能有中文
- 基类有QMainWindows QWidget QDialog三种,按需要选择
项目例程
//头文件
#include <QWidget> //窗口部件的头文件
#include <QPushButton> //包含按钮控件的头文件
#include <QLineEdit>// 编辑框的头文件
#include <QLabel> //标签的头文件
#include <QHBoxLayout> //水平布局管理器的头文件
class Widget : public QWidget //定义了一个类,这个类继承QWidget 是一个窗口部件
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
private:
QPushButton *m_BtnLogin; //声明一个按钮
QLineEdit *m_LineEdit; //声明编辑框
QLabel *m_Label; //声明标签
QHBoxLayout *HBoxLayout; //声明水平布局管理器
};
//源文件
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
this->setWindowTitle("aaa");//设置窗口部件的标题
// this->setFixedSize();//设置窗口的尺寸
this->resize(800,600);//可变的窗口尺寸
this->m_BtnLogin = new QPushButton(this); //给控件开空间,不加this指针控件无法显示
this->m_LineEdit = new QLineEdit(this);
this->m_Label = new QLabel(this);
this->m_BtnLogin->setText("login"); //设置控件的标题
this->m_BtnLogin->move(120,200); //移动控件到某个位置
this->m_LineEdit->move(200,100);
this->m_Label->setText("zhanghao");
this->m_Label->move(100,105);
this->HBoxLayout = new QHBoxLayout(this); //给水平布局管理器开空间
HBoxLayout->addWidget(m_Label); //添加成员
HBoxLayout->addWidget(m_LineEdit);
this->HBoxLayout->setContentsMargins(100,100,300,500); //设置管理器与四边的距离
this->setLayout(HBoxLayout); //水平布局管理器生效
}
同一级的水平布局管理器只有一个能生效
二、上课没有听懂或者没有理解的地方
无
三、当天学习的收获
学会了创建qt工程,以及使用qt完成简单的界面