Qt布局 day11

news2024/10/6 15:25:22

Qt布局 day11

布局基本流程

  • 布局管理器,可以管理widget,让他帮忙管理
    • 1.创建好我们想要布局的widgets
    • 2.我们创建QBoxLayout对象将其小部件添加到布局中
    • 3.我们调用QWidget::setLayout()将QBoxLayout对象安装到小部件上
    • 4.布局中国的小部件将重新设置父类,为上面调用setLayout()的窗口

盒子布局(BoxLayout)

  • QBoxLayout可以在水平方向或者垂直方向上排列控件,分别派生QHBoxLayout、QVBoxLayout子类

    • QHBoxLayout:水平布局,在水平方向上排列控件,左右排列
    • QVBoxLayout:垂直布局,在垂直方向上排列控件,上下排列
    • 水平布局、垂直布局除了构造时的方向(LeftToRight、TopToBottom)不同外其他均相同
  • 公有函数

序号函数&描述
1void addLayout(QLayout* layout,int stretch = 0)
将layout添加到框的末端,使用连续拉伸因子拉伸。
2void addSpacerItem(QSpacerItem * spacerItem)
将spaceeritem添加到该盒子布局的末尾,通常不使用这个函数,请使用addSpacing(int size)
3void addSpacing(int size)
添加一个大小为size的不可伸缩空间(QSpacerItem)到这个框布局的末尾
4void addStretch(int stretch = 0)
添加一个可伸缩空间(一个QSpacerItem),最小尺寸为零,拉伸因子stretch到这个框布局的末尾。
5void addStrut(int size)
限制盒子的垂直尺寸最小为size
6void addWidget(QWidget* widget,int stretch = 0,Qt::Alignment alignment = 0)
将小部件添加到此框布局的末尾,并使用拉伸因子拉伸和对齐对齐。
7void setDirection(QBoxLayout::Direction direction)
设置此布局的方向为direction。
8void setSpacing(int spacing)
设置小部件之间的间距
9void setStretch(int index,int stretch)
给index位置的控件设置拉伸因子stretch
10bool setStretchFactor(QWidget* widget,int stretch)
bool setStretchFactor(QWidget* widget,int stretch)
设置小部件的拉伸因子,如果在布局中发现小部件(不包括子布局),则返回true; 否则返回false。
  • 简单布局
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
class Widget :public QWidget
{
public:

	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{
		boxLayout();
		
	}
protected:
	void boxLayout()
	{
		//创建控件
		QLabel* userName = new QLabel("userName");
		QLineEdit* userNameEdit = new QLineEdit;

		//创建布局
		QBoxLayout* hLayout = new QHBoxLayout();
		
		//把控件加入布局
		hLayout->addWidget(userName);
		hLayout->addWidget(userNameEdit);

		//把布局交给窗口(布局到窗口上应用)
		setLayout(hLayout);
	}
	
private:
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	
	return a.exec();
}
#include "main.moc"
  • 运行结果,这个useName会居中在窗口,拖动窗口也会自动居中
    在这里插入图片描述

布局嵌套

#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
class Widget :public QWidget
{
public:

	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{
		boxLayout();
		
	}
protected:
	void boxLayout()
	{
		//创建控件
		QLabel* userName = new QLabel("userName");
		QLineEdit* userNameEdit = new QLineEdit;

		QLabel* userPassword = new QLabel("userPassword");
		QLineEdit* userPasswordEdit = new QLineEdit;

		//创建布局
		QBoxLayout* hLayout = new QHBoxLayout();
		QBoxLayout* hLayout2 = new QHBoxLayout();
		//把控件加入布局
		hLayout->addWidget(userName);
		hLayout->addWidget(userNameEdit);
		hLayout2->addWidget(userPassword);
		hLayout2->addWidget(userPasswordEdit);

		//嵌套
		QBoxLayout* vLayout = new QVBoxLayout();
		//将这两个水平布局添加到垂直布局中
		vLayout->addLayout(hLayout);
		vLayout->addLayout(hLayout2);

		//把布局交给窗口(布局到窗口上应用)
		this->setLayout(vLayout);
		
	}
	
private:
	
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	
	
	return a.exec();
}
#include "main.moc"
  • 运行结果,这两个控件依然是居中的
    在这里插入图片描述

布局的细节控制

  • QBoxLayout* hlayout = new QBoxLayout(QBoxLayout::Direction::LeftToRight, this);
    • QBoxLayout::Direction::LeftToRight:布局方向从左至右水平的
    • this:将布局部署到当前窗口
      在这里插入图片描述
  • 设置边距与间距
//设置控件边距(一般默认边距为9)
hlayout->setContentsMargins(0, 0, 0, 0);
//设置控件间距(一般默认间距为6)
hlayout->setSpacing(0);
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
class Widget :public QWidget
{
public:
	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{
		boxLayout();	
	}
protected:
	void boxLayout()
	{
		//创建控件		
		QPushButton* one = new QPushButton("one");
		QPushButton* tow = new QPushButton("tow");
		QPushButton* three = new QPushButton("three");
		QPushButton* four = new QPushButton("four");
		QPushButton* five = new QPushButton("five");

		//创建布局,布局方向从左至右水平的,并且设置布局到窗口
		QBoxLayout* hlayout = new QBoxLayout(QBoxLayout::Direction::LeftToRight, this);
		
		//设置控件边距(一般默认边距为9)
		hlayout->setContentsMargins(0, 0, 0, 0);
		//设置控件间距(一般默认间距为6)
		hlayout->setSpacing(0);

		//将控件添加进布局
		hlayout->addWidget(one);
		hlayout->addWidget(tow);
		hlayout->addWidget(three);
		hlayout->addWidget(four);
		hlayout->addWidget(five);
	}
private:
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);
	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述
  • 添加弹簧
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
class Widget :public QWidget
{
public:

	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{
		boxLayout();
		
	}
protected:
	void boxLayout()
	{
		//创建控件		
		QPushButton* one = new QPushButton("one");
		QPushButton* tow = new QPushButton("tow");
		QPushButton* three = new QPushButton("three");
		QPushButton* four = new QPushButton("four");
		QPushButton* five = new QPushButton("five");

		//创建布局,布局方向从左至右水平的,并且设置布局到窗口
		QBoxLayout* hlayout = new QBoxLayout(QBoxLayout::Direction::LeftToRight, this);
		
		//设置控件边距(一般默认边距为9)
		hlayout->setContentsMargins(0, 0, 0, 0);
		//设置控件间距(一般默认间距为6)
		hlayout->setSpacing(0);

		//将控件添加进布局
		hlayout->addStretch(1);		//添加弹簧(拉伸空间)
		hlayout->addWidget(one);
		hlayout->addWidget(tow);
		hlayout->addWidget(three);
		hlayout->addWidget(four);
		hlayout->addWidget(five);
		hlayout->addStretch(2);		//添加弹簧(拉伸空间)
	}
private:
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	
	
	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述
  • 其他操作
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
class Widget :public QWidget
{
public:

	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{
		boxLayout();		
	}
protected:
	void boxLayout()
	{
		//创建控件		
		QPushButton* one = new QPushButton("one");
		QPushButton* tow = new QPushButton("tow");
		QPushButton* three = new QPushButton("three");
		QPushButton* four = new QPushButton("four");
		QPushButton* five = new QPushButton("five");

		//设置按钮固定高度
		three->setFixedHeight(50);

		//创建布局,布局方向从左至右水平的,并且设置布局到窗口
		QBoxLayout* hlayout = new QBoxLayout(QBoxLayout::Direction::LeftToRight, this);
		
		//设置控件边距(一般默认边距为9)
		hlayout->setContentsMargins(0, 0, 0, 0);
		//设置控件间距(一般默认间距为6)
		hlayout->setSpacing(0);

		//将控件添加进布局
		hlayout->addStretch(1);		//添加弹簧(拉伸空间)
		hlayout->addWidget(one);
		hlayout->addWidget(tow, 0, Qt::AlignTop);//顶部对齐
		hlayout->addWidget(three);
		hlayout->addWidget(four, 0, Qt::AlignBottom);//底部对齐
		hlayout->addWidget(five);
		hlayout->addStretch(2);		//添加弹簧(拉伸空间)

		//设置布局方向
		//hlayout->setDirection(QBoxLayout::Direction::TopToBottom);//垂直布局
		//hlayout->setStretchFactor(one, 2); 给one设置拉伸系数
	}
private:
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述

网格布局(GridLayout)

  • 网格布局又称格栅布局(多行多列)
  • QGridLayout占用它可用的空间(通过它的父布局或parentWidget()),将它分成行和列,并将它管理的每个小部件放入正确的单元格中。
  • 网格布局需要自己布局,需要自己有分行列的概念
序号函数&描述
2void addLayout(QLayout *layout, int row, int column, Qt::Alignment alignment = 0)
void addLayout(QLayout *layout, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = 0)
将layout放置在网格中的位置(row、column)。 左上角的位置是(0,0)。
跨越多行/多列。 该单元格将从跨rowSpan行和columnSpan列的行、列开始。
3void addWidget(QWidget *widget, int row, int column, Qt::Alignment alignment = 0)
void addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment = 0)
同上
4void setRowStretch(int row, int stretch)
将row的拉伸因子设置为stretch
5void setColumnStretch(int column, int stretch)
将column的拉伸因子设置为stretch
6voidsetRowMinimumHeight(int row, int minSize)
将行的最小宽度设置为minSize像素。
7voidsetColumnMinimumWidth(int column, int minSize)
将列的最小宽度设置为minSize像素。
  • 网格布局概念
    在这里插入图片描述
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QGridLayout>
#include <QPixmap>
class Widget :public QWidget
{
public:

	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{
		LoginLayout();
		
	}
protected:
	void LoginLayout()
	{
		//创建组件
		QLabel* image = new QLabel;
		QLabel* accoutnText = new QLabel("账户:");
		QLabel* passwordText = new QLabel("密码:");
		QLineEdit* userAccount = new QLineEdit;
		QLineEdit* userPassword = new QLineEdit;
		QCheckBox* rememberPassword = new QCheckBox("记住密码");
		QCheckBox* autoLogin = new QCheckBox("自动登录");
		QPushButton* loginBtn = new QPushButton("登录");
		QPushButton* registerAccountBtn = new QPushButton("注册账户");
		QPushButton* retrievePasswordBtn = new QPushButton("找回密码");

		//组件的一些设置
		image->setPixmap(QPixmap(":/Resource/tubiao.ico"));
		image->setFixedSize(90, 90);
		image->setScaledContents(true);//设置图片的自动缩放到合适大小

		userAccount->setPlaceholderText("账户/手机号");//设置占位文本
		userPassword->setPlaceholderText("密码");
		
		//设置布局
		QGridLayout* gLayout = new QGridLayout(this);

		//添加组件到网格布局中
		gLayout->addWidget(image,0,0,3,1);					//设置到0行0列,占3行1列
		gLayout->addWidget(accoutnText, 0, 1);				//设置到0行1列,占0行0列
		gLayout->addWidget(passwordText, 1, 1);				//设置到1行1列,占0行0列

		
		gLayout->addWidget(userAccount, 0, 2, 1, 2);		//设置到0行2列,占1行2列
		gLayout->addWidget(userPassword, 1, 2, 1, 2);		//设置到1行2列,占1行2列

		gLayout->addWidget(rememberPassword, 2, 2);			//设置到2行2列,占0行0列
		gLayout->addWidget(autoLogin, 2, 3);				//设置到2行3列,占0行0列

		gLayout->addWidget(loginBtn, 3, 2, 1, 2);			//设置到3行2列,占1行2列

		gLayout->addWidget(registerAccountBtn, 0, 4);		//设置到0行4列,占0行0列
		gLayout->addWidget(retrievePasswordBtn, 1, 4);		//设置到1行4列,占0行0列

	}
	
private:
	
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	
	
	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述

表单布局(FormLayout)

  • QFormLayout类管理输入小部件的表单及其关联的标签

  • QFormLayout 是一个方便的布局类,它以两列形式布置其子项。 左列由标签组成,右列由“字段”小部件(行编辑器、旋转框等)组成。 传统上,这种两列表单布局是使用 QGridLayout 实现的。

  • QFormLayout 是一种更高级别的替代方案,具有以下优点:

    • 遵守不同平台的外观和感觉准则
      例如,macOS Aqua 和 KDE 指南指定标签应该右对齐,而 Windows 和 GNOME 应用程序通常使用左对齐。

    • 支持长行换行
      对于显示较小的设备,QFormLayout可以设置为对长行进行换行,甚至对所有行进行换行。

    • 创建标签-字段对,有非常方便的API
      我们可以通过addRow(const QString &labelText, QWidget *field)来创建一个带有给定文本的QLabel及QWidget控件行,它们可以自动的设置为伙伴关系。

序号函数&描述
1void addRow(QWidget* label,QWidget* field)
void addRow(QWidget* label,QLayout* field)
使用给定的label和field在此表单布局的底部添加新行
2void addRow(const QString &labelText, QWidget* field)
void addRow(const QString &labelText, QLayout* field)
这个重载会在后台自动创建一个以labelText作为文本的QLabel。 field被设置为新的QLabel的伙伴
3void addRow(QWidget widget)
void addRow(QLayout
layout)
在表单布局的末尾添加指定的小部件。 这个小部件横跨两列
9void setRowWrapPolicy(QFormLayout::RowWrapPolicy policy)
设置行换行策略
10void setSpacing(int spacing)
将垂直和水平间距设置为spacing。
11void setVerticalSpacing(int spacing)
将垂直间距设置为spacing
12void setWidget(int row, QFormLayout::ItemRole role, QWidget *widget)
将给定的row中的role设置为widget,必要时使用空行扩展布局。 如果单元格已被占用,则不插入小部件,并将错误消息发送到控制台。
  • 设置换行策略 void setRowWrapPolicy(QFormLayout::RowWrapPolicy policy)
枚举描述效果
QFormLayout::DontWrapRows字段总是放在它们的标签旁边(默认样式)在这里插入图片描述
QFormLayout::WrapLongRows标签有足够的空间适应,如果字段对的最小大小大于可用空间,输入框会被换到下一行在这里插入图片描述
QFormLayout::WrapAllRows字段总是在它们的标签下面。在这里插入图片描述
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QGridLayout>
#include <QPixmap>
#include <QFormLayout>
#include <QComboBox>
class Widget :public QWidget
{
public:
	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{
		FormLayout();
	}
protected:
	void FormLayout()
	{	
		QLineEdit* UserName = new QLineEdit;
		QLineEdit* UserPassword = new QLineEdit;
		QLineEdit* PhoneEdit = new QLineEdit;
		QLineEdit* EmailEdit = new QLineEdit;
		QCheckBox* GenderMan = new QCheckBox("男");
		QCheckBox* GenderWoman = new QCheckBox("女");
		QComboBox* Province = new QComboBox;
		for (int i = 0; i < 10; i++)
		{
			Province->addItem("小瓜" + QString::number(i) + "号", i);//这里的i是建立一种映射关系
		}
		connect(Province, &QComboBox::currentTextChanged, [=](const QString& text)
			{
				qDebug() << text;
				qDebug() << Province->currentData();//调用映射关系
			});

		QFormLayout* fLayout = new QFormLayout(this);
		//设置换行策略
		fLayout->setRowWrapPolicy(QFormLayout::RowWrapPolicy::WrapAllRows);

		//支持html标签
		fLayout->addRow("<font color = red size = 5>*</font>用户名:", UserName);
		fLayout->addWidget(new QLabel("<font color = gray size = 2>中文、英文、特殊字符<\font>"));

		fLayout->addRow("<font color = red>*</font>密  码:", UserPassword);
		fLayout->addWidget(new QLabel("<font color = gray size = 2>数字<\font>"));

		fLayout->addRow("<font color = red>*</font>手机号:", PhoneEdit);
		fLayout->addRow("邮  箱:", EmailEdit);

		//添加一个布局
		QHBoxLayout* hlayout = new QHBoxLayout;
		hlayout->addWidget(GenderMan);
		hlayout->addWidget(GenderWoman); 
		hlayout->addStretch();
		fLayout->addRow("性别",hlayout);
		
		fLayout->addRow(Province);
	}
private:
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);
	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述

堆栈布局(页面切换)

  • QStackedLayout继承自QLayout
  • QStackedLayout类提供了多页面切换的布局,一次只能看到一个界面。
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QGridLayout>
#include <QPixmap>
#include <QFormLayout>
#include <QComboBox>
#include <QStackedLayout>
#include <QButtonGroup>
class Widget :public QWidget
{
public:

	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{

		stackedLayout();
	}
protected:
	void LoginLayout(QWidget* parent)
	{
		//创建组件
		QLabel* image = new QLabel;
		QLabel* accoutnText = new QLabel("账户:");
		QLabel* passwordText = new QLabel("密码:");
		QLineEdit* userAccount = new QLineEdit;
		QLineEdit* userPassword = new QLineEdit;
		QCheckBox* rememberPassword = new QCheckBox("记住密码");
		QCheckBox* autoLogin = new QCheckBox("自动登录");
		QPushButton* loginBtn = new QPushButton("登录");
		QPushButton* registerAccountBtn = new QPushButton("注册账户");
		QPushButton* retrievePasswordBtn = new QPushButton("找回密码");

		//组件的一些设置
		image->setPixmap(QPixmap(":/Resource/tubiao.ico"));
		image->setFixedSize(90, 90);
		image->setScaledContents(true);//设置图片的自动缩放到合适大小

		userAccount->setPlaceholderText("账户/手机号");//设置占位文本
		userPassword->setPlaceholderText("密码");
		
		//设置布局
		QGridLayout* gLayout = new QGridLayout(parent);

		//添加组件到网格布局中
		gLayout->addWidget(image,0,0,3,1);					//设置到0行0列,占3行1列
		gLayout->addWidget(accoutnText, 0, 1);				//设置到0行1列,占0行0列
		gLayout->addWidget(passwordText, 1, 1);				//设置到1行1列,占0行0列

		
		gLayout->addWidget(userAccount, 0, 2, 1, 2);		//设置到0行2列,占1行2列
		gLayout->addWidget(userPassword, 1, 2, 1, 2);		//设置到1行2列,占1行2列

		gLayout->addWidget(rememberPassword, 2, 2);			//设置到2行2列,占0行0列
		gLayout->addWidget(autoLogin, 2, 3);				//设置到2行3列,占0行0列

		gLayout->addWidget(loginBtn, 3, 2, 1, 2);			//设置到3行2列,占1行2列

		gLayout->addWidget(registerAccountBtn, 0, 4);		//设置到0行4列,占0行0列
		gLayout->addWidget(retrievePasswordBtn, 1, 4);		//设置到1行4列,占0行0列

	}
	void FormLayout(QWidget* parent)
	{
		QLineEdit* UserName = new QLineEdit;
		QLineEdit* UserPassword = new QLineEdit;
		QLineEdit* PhoneEdit = new QLineEdit;
		QLineEdit* EmailEdit = new QLineEdit;
		QCheckBox* GenderMan = new QCheckBox("男");
		QCheckBox* GenderWoman = new QCheckBox("女");
		QComboBox* Province = new QComboBox;
		for (int i = 0; i < 10; i++)
		{
			Province->addItem("小瓜" + QString::number(i) + "号", i);//这里的i是建立一种映射关系
		}
		connect(Province, &QComboBox::currentTextChanged, [=](const QString& text)
			{
				qDebug() << text;
		qDebug() << Province->currentData();//调用映射关系
			});

		QFormLayout* fLayout = new QFormLayout(parent);
		//设置换行策略
		fLayout->setRowWrapPolicy(QFormLayout::RowWrapPolicy::WrapAllRows);

		//支持html标签
		fLayout->addRow("<font color = red size = 5>*</font>用户名:", UserName);
		fLayout->addWidget(new QLabel("<font color = gray size = 2>中文、英文、特殊字符<\font>"));

		fLayout->addRow("<font color = red>*</font>密  码:", UserPassword);
		fLayout->addWidget(new QLabel("<font color = gray size = 2>数字<\font>"));

		fLayout->addRow("<font color = red>*</font>手机号:", PhoneEdit);
		fLayout->addRow("邮  箱:", EmailEdit);

		//添加一个布局
		QHBoxLayout* hlayout = new QHBoxLayout;
		hlayout->addWidget(GenderMan);
		hlayout->addWidget(GenderWoman);
		hlayout->addStretch();
		fLayout->addRow("性别", hlayout);

		fLayout->addRow(Province);
	}
	void stackedLayout()
	{
		//创建按钮组,来管理多个按钮
		QButtonGroup* BtnGroup = new QButtonGroup(this);
		BtnGroup->addButton(new QPushButton("page1"), 0); 
		BtnGroup->addButton(new QPushButton("page2"), 1); 

		//创建一个水平盒子布局来布局按钮
		QHBoxLayout* hLayout = new QHBoxLayout;
		hLayout->addWidget(BtnGroup->button(0));
		hLayout->addWidget(BtnGroup->button(1));

		//创建一个堆栈布局用来管理多个页面
		QStackedLayout* sLayout = new QStackedLayout;
		sLayout->addWidget(CreatePage(0));
		sLayout->addWidget(CreatePage(1));

		//创建一个垂直盒子布局来布局水平盒子布局于堆栈布局
		QVBoxLayout* vLayout = new QVBoxLayout;
		vLayout->addLayout(hLayout);
		vLayout->addLayout(sLayout);

		//设置布局
		setLayout(vLayout);

		//切换页面
		qDebug() << sLayout->count();//获取页面数量
		

		connect(BtnGroup, &QButtonGroup::idClicked, this, [=](int Id) {
			
			sLayout->setCurrentIndex(Id);
		});
	}
	
private:
	QWidget* CreatePage(int Id)
	{
		if (Id == 0)
		{
			QWidget* page = new QWidget;
			LoginLayout(page);
			return page;
		}
		else if (Id == 1)
		{
			QWidget* page = new QWidget;
			FormLayout(page);
			return page;
		}
		return nullptr;
	}
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	
	
	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述
    在这里插入图片描述

窗口分割器(Splitter)

  • QSplitter类实现了一个分离小部件。 splitter允许用户通过拖动子部件之间的边界来控制它们的大小。 任何数量的小部件都可以由单个拆分器控制。QSplitter的典型用法是创建几个小部件并使用 insertWidget()或addWidget()添加它们。
#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QGridLayout>
#include <QPixmap>
#include <QFormLayout>
#include <QComboBox>
#include <QStackedLayout>
#include <QButtonGroup>
#include <QSplitter>
#include <QPlainTextEdit>
class Widget :public QWidget
{
public:

	Widget(QWidget* parent = nullptr) :QWidget(parent)
	{
		splitter();
	}
protected:
	void LoginLayout(QWidget* parent)
	{
		//创建组件
		QLabel* image = new QLabel;
		QLabel* accoutnText = new QLabel("账户:");
		QLabel* passwordText = new QLabel("密码:");
		QLineEdit* userAccount = new QLineEdit;
		QLineEdit* userPassword = new QLineEdit;
		QCheckBox* rememberPassword = new QCheckBox("记住密码");
		QCheckBox* autoLogin = new QCheckBox("自动登录");
		QPushButton* loginBtn = new QPushButton("登录");
		QPushButton* registerAccountBtn = new QPushButton("注册账户");
		QPushButton* retrievePasswordBtn = new QPushButton("找回密码");

		//组件的一些设置
		image->setPixmap(QPixmap(":/Resource/tubiao.ico"));
		image->setFixedSize(90, 90);
		image->setScaledContents(true);//设置图片的自动缩放到合适大小

		userAccount->setPlaceholderText("账户/手机号");//设置占位文本
		userPassword->setPlaceholderText("密码");
		
		//设置布局
		QGridLayout* gLayout = new QGridLayout(parent);

		//添加组件到网格布局中
		gLayout->addWidget(image,0,0,3,1);					//设置到0行0列,占3行1列
		gLayout->addWidget(accoutnText, 0, 1);				//设置到0行1列,占0行0列
		gLayout->addWidget(passwordText, 1, 1);				//设置到1行1列,占0行0列

		
		gLayout->addWidget(userAccount, 0, 2, 1, 2);		//设置到0行2列,占1行2列
		gLayout->addWidget(userPassword, 1, 2, 1, 2);		//设置到1行2列,占1行2列

		gLayout->addWidget(rememberPassword, 2, 2);			//设置到2行2列,占0行0列
		gLayout->addWidget(autoLogin, 2, 3);				//设置到2行3列,占0行0列

		gLayout->addWidget(loginBtn, 3, 2, 1, 2);			//设置到3行2列,占1行2列

		gLayout->addWidget(registerAccountBtn, 0, 4);		//设置到0行4列,占0行0列
		gLayout->addWidget(retrievePasswordBtn, 1, 4);		//设置到1行4列,占0行0列

	}
	void FormLayout(QWidget* parent)
	{
		QLineEdit* UserName = new QLineEdit;
		QLineEdit* UserPassword = new QLineEdit;
		QLineEdit* PhoneEdit = new QLineEdit;
		QLineEdit* EmailEdit = new QLineEdit;
		QCheckBox* GenderMan = new QCheckBox("男");
		QCheckBox* GenderWoman = new QCheckBox("女");
		QComboBox* Province = new QComboBox;
		for (int i = 0; i < 10; i++)
		{
			Province->addItem("小瓜" + QString::number(i) + "号", i);//这里的i是建立一种映射关系
		}
		connect(Province, &QComboBox::currentTextChanged, [=](const QString& text)
			{
				qDebug() << text;
		qDebug() << Province->currentData();//调用映射关系
			});

		QFormLayout* fLayout = new QFormLayout(parent);
		//设置换行策略
		fLayout->setRowWrapPolicy(QFormLayout::RowWrapPolicy::WrapAllRows);

		//支持html标签
		fLayout->addRow("<font color = red size = 5>*</font>用户名:", UserName);
		fLayout->addWidget(new QLabel("<font color = gray size = 2>中文、英文、特殊字符<\font>"));

		fLayout->addRow("<font color = red>*</font>密  码:", UserPassword);
		fLayout->addWidget(new QLabel("<font color = gray size = 2>数字<\font>"));

		fLayout->addRow("<font color = red>*</font>手机号:", PhoneEdit);
		fLayout->addRow("邮  箱:", EmailEdit);

		//添加一个布局
		QHBoxLayout* hlayout = new QHBoxLayout;
		hlayout->addWidget(GenderMan);
		hlayout->addWidget(GenderWoman);
		hlayout->addStretch();
		fLayout->addRow("性别", hlayout);

		fLayout->addRow(Province);
	}
	void stackedLayout()
	{
		//创建一个按钮组用来管理按钮
		QButtonGroup* BtnGroup = new QButtonGroup(this);
		BtnGroup->addButton(new QPushButton("page1"), 0);
		BtnGroup->addButton(new QPushButton("page2"), 1);
		
		//创建一个水平布局来管理这两个按钮
		QHBoxLayout* bLayout = new QHBoxLayout;
		bLayout->addWidget(BtnGroup->button(0));
		bLayout->addWidget(BtnGroup->button(1));


		//创建一个堆栈布局来切换不同页面
		QStackedLayout* sLayout = new QStackedLayout;
		sLayout->addWidget(CreatePage(0));
		sLayout->addWidget(CreatePage(1));

		//创建一个垂直布局来管理上面两个布局
		QVBoxLayout* vLayout = new QVBoxLayout;
		vLayout->addLayout(bLayout);
		vLayout->addLayout(sLayout);


		setLayout(vLayout);

		connect(BtnGroup, &QButtonGroup::idClicked, [=](int Id) {

				sLayout->setCurrentIndex(Id);
			});
	
	}
	void splitter()
	{
		//创建分割器
		QSplitter* sp = new QSplitter(this);
		sp->addWidget(CreatePage(0));
		sp->addWidget(CreatePage(1));
		sp->setCollapsible(0, false);

		//嵌套分割器,设置分割类别
		QSplitter* vsp = new QSplitter(Qt::Orientation::Vertical);
		vsp->addWidget(sp);
		vsp->addWidget(new QPlainTextEdit);

		//设置布局
		QHBoxLayout* hLayout = new QHBoxLayout(this);
		hLayout->addWidget(vsp);

	}
	
private:
	QWidget* CreatePage(int Id)
	{
		if (Id == 0)
		{
			QWidget* page = new QWidget;
			LoginLayout(page);
			return page;
		}
		else if (Id == 1)
		{
			QWidget* page = new QWidget;
			FormLayout(page);
			return page;
		}
		return nullptr;
	}
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);
	Widget w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();
	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述

登录页面小例子

登录页面

#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QGridLayout>
#include <QPixmap>
#include <QFormLayout>
#include <QComboBox>
#include <QStackedLayout>
#include <QButtonGroup>
#include <QSplitter>
#include <QPlainTextEdit>
#include <QDialog>
#include <QSettings>
#include <QDesktopServices>

class LoginDlg :public QDialog
{
public:

	LoginDlg(QWidget* parent = nullptr) :QDialog(parent)
	{

		LoginLayout();
		ReadConfig();

	}

	void LoginLayout()
	{
		image = new QLabel;
		accoutnText = new QLabel("账户:");
		passwordText = new QLabel("密码:");
		userAccount = new QLineEdit;
		userPassword = new QLineEdit;
		rememberPasswordChx = new QCheckBox("记住密码");
		AutoLogin = new QCheckBox("自动登录");
		loginBtn = new QPushButton("登录");
		registerAccountBtn = new QPushButton("注册账户");
		retrievePasswordBtn = new QPushButton("找回密码");

		userPassword->setEchoMode(QLineEdit::EchoMode::Password);

		//组件的一些设置
		image->setPixmap(QPixmap(":/Resource/tubiao.ico"));
		image->setFixedSize(90, 90);
		image->setScaledContents(true);//设置图片的自动缩放到合适大小

		userAccount->setPlaceholderText("账户/手机号");//设置占位文本
		userPassword->setPlaceholderText("密码");

		//设置布局
		QGridLayout* gLayout = new QGridLayout;

		//添加组件到网格布局中
		gLayout->addWidget(image, 0, 0, 3, 1);					//设置到0行0列,占3行1列
		gLayout->addWidget(accoutnText, 0, 1);				//设置到0行1列,占0行0列
		gLayout->addWidget(passwordText, 1, 1);				//设置到1行1列,占0行0列


		gLayout->addWidget(userAccount, 0, 2, 1, 2);		//设置到0行2列,占1行2列
		gLayout->addWidget(userPassword, 1, 2, 1, 2);		//设置到1行2列,占1行2列

		gLayout->addWidget(rememberPasswordChx, 2, 2);			//设置到2行2列,占0行0列
		gLayout->addWidget(AutoLogin, 2, 3);				//设置到2行3列,占0行0列

		gLayout->addWidget(loginBtn, 3, 2, 1, 2);			//设置到3行2列,占1行2列

		gLayout->addWidget(registerAccountBtn, 0, 4);		//设置到0行4列,占0行0列
		gLayout->addWidget(retrievePasswordBtn, 1, 4);		//设置到1行4列,占0行0列

		setLayout(gLayout);

		connect(loginBtn, &QPushButton::clicked, this, &LoginDlg::OnLogin);

		connect(registerAccountBtn, &QPushButton::clicked, this, [=]() {
			QDesktopServices::openUrl(QUrl("https://blog.csdn.net/qq_44924388/article/details/133850918?spm=1001.2014.3001.5501"));
			});
		connect(retrievePasswordBtn, &QPushButton::clicked, this, [=]() {
			QDesktopServices::openUrl(QUrl("https://blog.csdn.net/qq_44924388/article/details/133850918?spm=1001.2014.3001.5501"));
			});
	}

	//记住密码
	void RememberPassword()
	{
		QSettings settings("config.ini", QSettings::IniFormat);
		//账户在第一次登录后永远记住,是否选择了记住密码与自动登录,要看用户是否选择
		settings.setValue("account", userAccount->text());
		settings.setValue("RememberPassword", rememberPasswordChx->isChecked());
		settings.setValue("autoLogin", AutoLogin->isChecked());
		
		if (!rememberPasswordChx->isChecked())
		{
			//如果去除了是否记住密码就清除掉ini文件中的密码
			settings.setValue("password", QVariant());
		}
		else
		{
			//设置配置文件。将保存的密码放入配置文件
			settings.setValue("password", userPassword->text());
		}
	}

	//读取配置文件
	void ReadConfig()
	{
		QSettings settings("config.ini", QSettings::IniFormat);
		userAccount->setText(settings.value("account").toString());
		//如果配置文件中的记住密码为真就读取密码,并且填写
		bool isRemembel = settings.value("RememberPassword", false).toBool();
		if (isRemembel)
		{

			rememberPasswordChx->setChecked(true);
			userPassword->setText(settings.value("password").toString());
			//如果自动登录为真
			if(settings.value("autoLogin",false).toBool())
			{
				//就让它自己点自己
				loginBtn->click();
			}
		}
	}

public: //slots
	void OnLogin()
	{
		auto accout = userAccount->text();
		auto password = userPassword->text();
		if (true)
		{
			qDebug() << accout << password;
			RememberPassword();
		}
	}

private:
	//组件
	QLabel* image{};
	QLabel* accoutnText{};
	QLabel* passwordText{};
	QLineEdit* userAccount{};
	QLineEdit* userPassword{};
	QCheckBox* rememberPasswordChx{};
	QCheckBox* AutoLogin{};
	QPushButton* loginBtn{};
	QPushButton* registerAccountBtn{};
	QPushButton* retrievePasswordBtn{};
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	LoginDlg w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();

	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述

登录成功后切换布局

#include <QApplication>
#include <QWidget>
#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QCheckBox>
#include <QGridLayout>
#include <QPixmap>
#include <QFormLayout>
#include <QComboBox>
#include <QStackedLayout>
#include <QButtonGroup>
#include <QSplitter>
#include <QPlainTextEdit>
#include <QDialog>
#include <QSettings>
#include <QDesktopServices>

class LoginDlg :public QDialog
{
public:

	LoginDlg(QWidget* parent = nullptr) :QDialog(parent)
	{

		stackedLayout();
		ReadConfig();

	}

	void HBoxLAyout(QWidget* parent)
	{
		xiaogua = new QLabel;
		xiaogua->setPixmap(QPixmap(":/Resource/xiaogua.bmp"));
		xiaogua->setFixedSize(170, 170);
		xiaogua->setScaledContents(true);

		QHBoxLayout* hLayout = new QHBoxLayout(parent);
		hLayout->addWidget(xiaogua);
	}

	void LoginLayout(QWidget* parent)
	{

		image = new QLabel;
		accoutnText = new QLabel("账户:");
		passwordText = new QLabel("密码:");
		userAccount = new QLineEdit;
		userPassword = new QLineEdit;
		rememberPasswordChx = new QCheckBox("记住密码");
		AutoLogin = new QCheckBox("自动登录");
		loginBtn = new QPushButton("登录");
		registerAccountBtn = new QPushButton("注册账户");
		retrievePasswordBtn = new QPushButton("找回密码");

		userPassword->setEchoMode(QLineEdit::EchoMode::Password);

		//组件的一些设置
		image->setPixmap(QPixmap(":/Resource/tubiao.ico"));
		image->setFixedSize(90, 90);
		image->setScaledContents(true);//设置图片的自动缩放到合适大小

		userAccount->setPlaceholderText("账户/手机号");//设置占位文本
		userPassword->setPlaceholderText("密码");

		//设置布局
		QGridLayout* gLayout = new QGridLayout(parent);

		//添加组件到网格布局中
		gLayout->addWidget(image, 0, 0, 3, 1);					//设置到0行0列,占3行1列
		gLayout->addWidget(accoutnText, 0, 1);				//设置到0行1列,占0行0列
		gLayout->addWidget(passwordText, 1, 1);				//设置到1行1列,占0行0列


		gLayout->addWidget(userAccount, 0, 2, 1, 2);		//设置到0行2列,占1行2列
		gLayout->addWidget(userPassword, 1, 2, 1, 2);		//设置到1行2列,占1行2列

		gLayout->addWidget(rememberPasswordChx, 2, 2);			//设置到2行2列,占0行0列
		gLayout->addWidget(AutoLogin, 2, 3);				//设置到2行3列,占0行0列

		gLayout->addWidget(loginBtn, 3, 2, 1, 2);			//设置到3行2列,占1行2列

		gLayout->addWidget(registerAccountBtn, 0, 4);		//设置到0行4列,占0行0列
		gLayout->addWidget(retrievePasswordBtn, 1, 4);		//设置到1行4列,占0行0列

		//setLayout(gLayout);

		connect(loginBtn, &QPushButton::clicked, this, &LoginDlg::OnLogin);

		connect(registerAccountBtn, &QPushButton::clicked, this, [=]() {
			QDesktopServices::openUrl(QUrl("https://blog.csdn.net/qq_44924388/article/details/133850918?spm=1001.2014.3001.5501"));
			});
		connect(retrievePasswordBtn, &QPushButton::clicked, this, [=]() {
			QDesktopServices::openUrl(QUrl("https://blog.csdn.net/qq_44924388/article/details/133850918?spm=1001.2014.3001.5501"));
			});
	}

	void stackedLayout()
	{
		
		QStackedLayout* sLayout = new QStackedLayout;
		sLayout->addWidget(CreateWidget(0));
		sLayout->addWidget(CreateWidget(1));
		
		QHBoxLayout* hLayout = new QHBoxLayout;
		hLayout->addLayout(sLayout);

		//设置布局
		setLayout(hLayout);

		connect(loginBtn, &QPushButton::clicked, this, [=]()
			{
				if (accout == "xiaogua" && password == "123456")
				{
					sLayout->setCurrentIndex(1);
				}
			});
	}

	//记住密码
	void RememberPassword()
	{
		QSettings settings("config.ini", QSettings::IniFormat);
		//账户在第一次登录后永远记住,是否选择了记住密码与自动登录,要看用户是否选择
		settings.setValue("account", userAccount->text());
		settings.setValue("RememberPassword", rememberPasswordChx->isChecked());
		settings.setValue("autoLogin", AutoLogin->isChecked());
		
		if (!rememberPasswordChx->isChecked())
		{
			//如果去除了是否记住密码就清除掉ini文件中的密码
			settings.setValue("password", QVariant());
		}
		else
		{
			//设置配置文件。将保存的密码放入配置文件
			settings.setValue("password", userPassword->text());
		}
	}

	//读取配置文件
	void ReadConfig()
	{
		QSettings settings("config.ini", QSettings::IniFormat);
		userAccount->setText(settings.value("account").toString());
		//如果配置文件中的记住密码为真就读取密码,并且填写
		bool isRemembel = settings.value("RememberPassword", false).toBool();
		if (isRemembel)
		{

			rememberPasswordChx->setChecked(true);
			userPassword->setText(settings.value("password").toString());
			//如果自动登录为真
			if(settings.value("autoLogin",false).toBool())
			{
				//就让它自己点自己
				loginBtn->click();
			}
		}
	}
	//创建两个布局
	QWidget* CreateWidget(int Id)
	{
		if (Id == 0)
		{
			QWidget* page = new QWidget;
			LoginLayout(page);
			return page;
		}
		if (Id == 1)
		{
			QWidget* page = new QWidget;
			HBoxLAyout(page);
			return page;
		}
	}

public: //slots
	void OnLogin()
	{
		accout = userAccount->text();
		password = userPassword->text();
		if (accout == "xiaogua" && password == "123456")
		{
			qDebug() << accout << password;
			RememberPassword();
		}
		else
		{
			qDebug() << "密码错误";
		}
	}

private:
	//组件
	QLabel* image{};
	QLabel* accoutnText{};
	QLabel* passwordText{};
	QLineEdit* userAccount{};
	QLineEdit* userPassword{};
	QCheckBox* rememberPasswordChx{};
	QCheckBox* AutoLogin{};
	QPushButton* loginBtn{};
	QPushButton* registerAccountBtn{};
	QPushButton* retrievePasswordBtn{};

	QLabel* xiaogua{};
	QString accout;
	QString password;
};

int main(int argc, char* argv[])
{
	QApplication a(argc, argv);

	LoginDlg w;
	w.setWindowIcon(QIcon(":/Resource/tubiao.ico"));
	w.show();

	return a.exec();
}
#include "main.moc"
  • 运行结果
    在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1136569.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

02 功能模块与技术选型

本专栏将从基础开始&#xff0c;循序渐进&#xff0c;以实战为线索&#xff0c;逐步深入SpringSecurity相关知识相关知识&#xff0c;打造完整的SpringSecurity学习步骤&#xff0c;提升工程化编码能力和思维能力&#xff0c;写出高质量代码。希望大家都能够从中有所收获&#…

PMP考试都是什么题型?

这里要讲一些关于新考纲的知识点&#xff0c;这些内容都会在考试中出现。为了快速作答&#xff0c;我们要抓住主要的点&#xff0c;优先回答自信的题目。 1、不需要全都答对180道题。 按照二八法则&#xff0c;只要能答对80%的题目&#xff0c;容错率大约是20%&#xff08;约…

亚马逊卖家必备:自养号测评如何帮助新店铺脱颖而出?

亚马逊是全球最大的电商平台之一&#xff0c;成为亚马逊新店铺的卖家是许多商家的梦想。然而&#xff0c;在一个庞大的市场中脱颖而出并吸引客户并不容易。所以&#xff0c;如何在亚马逊上成功推广新店铺呢?让我们来探讨一下&#xff0c;有哪些技巧可以帮助您实现这个目标。 …

UE5 C++自定义Http节点获得Header数据

一、新建C文件 选择All Classes&#xff0c;选择父类BlueprintFunctionLibrary&#xff0c;命名为SendHttpRequest。 添加Http支持 代理回调的参数使用DECLARE_DYNAMIC_DELEGATE_TwoParam定义&#xff0c;第一参数是代理类型&#xff0c;后面是参数1类型&#xff0c;参数1&…

2-Java进阶知识总结-2-递归-异常-流-File

文章目录 Java SE进阶知识总结-2Objects、Math、System、BigDecimalObjectsMathSystemBigDecimal 包装类基本数据类型对应的包装类自动拆箱和自动装箱包装类常见问题 时间类JDK8&#xff08;-&#xff09;JDK8&#xff08;&#xff09;日历类&#xff08;获取当前时间&#xff…

7年阿里测试经验之谈 —— 用UI自动化测试实现元素定位!

随着IT行业的发展&#xff0c;产品愈渐复杂&#xff0c;web端业务及流程更加繁琐&#xff0c;目前UI测试仅是针对单一页面&#xff0c;操作量大。为了满足多页面功能及流程的需求及节省工时&#xff0c;设计了这款UI 自动化测试程序。旨在提供接口&#xff0c;集成到蜗牛自动化…

BUUCTF 文件中的秘密 1

BUUCTF:https://buuoj.cn/challenges 题目描述&#xff1a; 小明经常喜欢在文件中藏一些秘密。时间久了便忘记了&#xff0c;你能帮小明找到该文件中的秘密吗&#xff1f; 密文&#xff1a; 下载附件&#xff0c;解压得到JPEG图片。 解题思路&#xff1a; 1、根据题目提示…

预训练+微调 逆合成预测

【JCIM 2020】数据增强预训练基于模板 Template methods Figure 1. 预训练微调 workflow 首先&#xff0c;通过增强的反应数据&#xff08;真实存在的数据计算机生成的反应数据&#xff09;进行Pretrain Encoder A&#xff0c; 2、只使用真实反应数据对Pretrain Encoder A 进…

最小生成树专题1 最小生成树-Prim算法

题目&#xff1a; 样例1&#xff1a; 输入 4 5 0 1 3 0 2 2 0 3 3 2 3 1 1 2 1 输出 4 样例2&#xff1a; 输入 3 1 0 1 1 输出 -1 思路&#xff1a; Prim 算法和 朴素版的 Dijkstra 有点类似&#xff0c;也叫做 朴素版Prim算法&#xff0c;但也还是有点区别。 Dijkstra 中…

​CRM系统如何选型?

不少企业都想要使用CRM客户管理系统&#xff0c;但往往在CRM选型阶段就被折腾的五迷三道。CRM系统选型难在哪里&#xff1f;下面我们从企业用户和CRM厂商两方面进行分析&#xff0c;来说说关于CRM系统选型的那些事。 企业自身原因&#xff1a; 1、认知偏差 看到一个观点&…

GNN图神经网络入门

1.为什么会提出图神经网络&#xff1f; 答&#xff1a;为了处理图Graph这种特殊的数据结构。 2.为什么要与神经网络搭上关系&#xff1f; 答&#xff1a;利用神经网络能够拟合任意函数的能力&#xff08;或者理解为强大的为特征变换能力&#xff09;。 3.图神经网络的最终目的是…

Ajax、Json深入浅出,及原生Ajax及简化版Ajax

Ajax 1.路径介绍 1.1 JavaWeb中的路径 在JavaWeb中&#xff0c;路径分为相对路径和绝对路径两种&#xff1a; 相对路径&#xff1a; ./ 表示当前目录(可省略) ../ 表示当前文件所在目录的上一级目录 绝对路径&#xff1a; http://ip:port/工程名/资源路径 2.2 在JavaWeb中…

EG网关串口连接台达PLC

EG网关串口连接台达PLC 前言&#xff1a;台达PLC是一款国产优秀的可编程控制器&#xff0c;广泛应于工业控制领域&#xff0c;是一款性能高&#xff0c;运行稳定的控制器。此次我们要把台达DVP-ES系列PLC通过modbus驱动连接到EMCP物联网云平台&#xff08;简称EMCP&#xff09;…

一些额外且好用的 icon 图库

一些额外且好用的 icon 图库 之前偶然逛到 最佳 Icon 图标库推荐&#xff0c;收藏等于学会&#xff0c;这个真的挺好用的&#xff0c;不过这里的 icon 都是和 React 组件绑定了&#xff0c;额外补充一些不和框架绑定的图库 font awesome 这个应该用的人满多的&#xff0c;算…

基于springboot实现时间管理系统项目【项目源码+论文说明】

基于springboot实现时间管理系统演示 摘要 在Internet高速发展的今天&#xff0c;我们生活的各个领域都涉及到计算机的应用&#xff0c;其中包括时间管理系统的网络应用&#xff0c;在外国时间管理系统已经是很普遍的方式&#xff0c;不过国内的管理系统可能还处于起步阶段。时…

KNN 和 SVM 图片分类 任务 代码及细节分享

使用KNN (K-最近邻) 方法进行图像分类也是一个常见的选择。以下是 使用sklearn的KNeighborsClassifier进行图像分类的Python脚本&#xff1a; import os import cv2 import numpy as np import logging from sklearn.neighbors import KNeighborsClassifier from sklearn.met…

jdbc 中 Statement 不能避免注入式漏洞(SQL注入漏洞)

注入式漏洞 也称为 SQL注入漏洞&#xff0c;是一种常见的应用程序安全漏洞。当应用程序将用户输入的数据直接 拼接 到SQL查询语句中&#xff0c;而未对输入进行有效的过滤和转义时&#xff0c;攻击者可通过构造恶意的输入来执行非法的SQL语句&#xff0c;从而实现对应用程序的攻…

esp32c3-microPython开发固件烧录用户手册

esp32c3-microPython开发固件烧录用户手册1.4 文章目录 esp32c3-microPython开发固件烧录用户手册1.4烧录所需硬件软件工具Thonnyflash_download_tools 插座与USB转TTL模块之间接线esp32-C3版本插座&#xff08;底板4针&#xff09; 下载对应的 MicroPython固件烧录MicroPython…

grafana InfluxDB returned error: error reading influxDB 400错误解决

问题&#xff1a; 如图提示错误解决 确认自己的docker容器是否配置了以下3个字段 DOCKER_INFLUXDB_INIT_USERNAMExxx DOCKER_INFLUXDB_INIT_PASSWORDyyy DOCKER_INFLUXDB_INIT_ADMIN_TOKENzzz 如果有&#xff0c;在grafana中需要添加header配置Header: Authorization , Value…

将自己本地项目上传到git,IDEA图文操作

文章目录 一、初始化git仓库二、gitee创建仓库三、输入自己仓库的地址四、在添加所修改的文件可能的错误 五、合并需上传文件六、上传参考文档 一、初始化git仓库 在自己的项目中&#xff0c;命令行中输入 git init二、gitee创建仓库 新建仓库 设置仓库参数&#xff0c;设置…