【接口封装】——13、登录窗口的标题栏内容设置

解释:

**1、封装内容:**图标、文本内容、宽度

**2、ui.iconLabel:**在UI文件中的自定义命名

3、引入头文件:#include<qpixmap.h>

函数定义:

cpp 复制代码
#pragma once

#include <QWidget>
#include "ui_TitleBar.h"

class TitleBar : public QWidget
{
	Q_OBJECT

public:
	TitleBar(QWidget *parent = nullptr);
	~TitleBar();

	//设置标题栏图标接口
	void setTitleIcon(const QString& filepath);

	//内容设置接口
	void setTitleContent(const QString& titleContent);

	//宽度设置接口
	void setTitleWidth(int width);



private:
	Ui::TitleBarClass ui;
};

源代码:

cpp 复制代码
#include "TitleBar.h"
#include<qpixmap.h>

TitleBar::TitleBar(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
}

TitleBar::~TitleBar()
{}

void TitleBar::setTitleIcon(const QString & filepath)
{
	//引入:#include<qpixmap.h>
	QPixmap pix(filepath);

	//iconLabel:ui文件中的自定义命名
	ui.iconLabel->setFixedSize(pix.size());
	ui.iconLabel->setPixmap(pix);

}

void TitleBar::setTitleContent(const QString & titleContent)
{
	ui.titleContent->setText(titleContent);
}

void TitleBar::setTitleWidth(int width)
{
	this->setFixedWidth(width);
}
相关推荐
wefg12 小时前
【项目】C++ 基于 Vibe Coding 的 OJ 平台
开发语言·c++
郝学胜-神的一滴9 小时前
Effective STL 条款 07:指针容器销毁前先删除
开发语言·c++·vscode·leetcode·rpc·visual studio
Lucas. Wáng12 小时前
Qt学习之旅
c++·qt
星恒随风12 小时前
从0实现C++ AI大模型接入SDK(二):AI知识科普——从图灵测试到ChatGPT,人工智能的发展历程
linux·c++·人工智能·笔记·chatgpt
青少儿编程课堂12 小时前
蓝桥杯真题解析:三维偏序的CDQ分治(全国青少年信息素养大赛与电子学会编程考级)
c++·python·算法·bfs·信息学竞赛
csdn_aspnet14 小时前
C++ 求给定点集的简单闭合路径(Find Simple Closed Path for a given set of points)
c++
艾莉丝努力练剑14 小时前
【AI接入大模型SDK】解决接口连接异常问题
前端·c++·人工智能·学习·ai·架构
Severus_black14 小时前
【C++初阶】模板进阶
c语言·c++·学习
艾莉丝努力练剑16 小时前
【AI接入大模型SDK】Markdown格式解析
前端·c++·人工智能·学习·ai·架构
逐光沧海16 小时前
数据结构-链表习题(C++)
数据结构·c++·链表