当前位置:网站首页>QT添加资源文件、样式表、qss文件使用
QT添加资源文件、样式表、qss文件使用
2022-08-03 01:58:00 【Lee Neo】
添加资源文件参考步骤:
正点原子开发指南的7.1.3节;
样式表:
搜索stylesheet的步骤:


样式表:添加背景图片
设置字体的格式:
QLabel {
font-size:30pt;
color:red;
}设置背景的格式:

qss文件
添加qss文件参考开发指南7.1.3
用代码直接实现

用qss文件实现
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QLabel>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
//this->setStyleSheet("QWidget{background-color:black}");
QLabel *label = new QLabel(this);
label->setGeometry(0,0,100,100);
// label->setStyleSheet("QLabel{background-color:red}");
QLabel *label1 = new QLabel(this);
label1->setGeometry(100,100,100,100);
label1->setObjectName("label1");
// label1->setStyleSheet("QLabel{background-color:green}");
this->resize(800,480);
}
Widget::~Widget()
{
delete ui;
}
main.cpp
#include "widget.h"
#include <QApplication>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
/* 指定文件 */
QFile file(":/style.qss");
/* 判断文件是否存在 */
if (file.exists() ) {
/* 以只读的方式打开 */
file.open(QFile::ReadOnly);
/* 以字符串的方式保存读出的结果 */
QString styleSheet = QLatin1String(file.readAll());
/* 设置全局样式 */
qApp->setStyleSheet(styleSheet);
/* 关闭文件 */
file.close();
}
Widget w;
w.show();
return a.exec();
}
style.qss
边栏推荐
- numpy PIL tensor之间的相互转换
- Wireshark data capture and analysis of the transport layer protocol (TCP protocol)
- PHICOMM(斐讯)N1盒子 - Armbian5.77(Debian 9)基本配置
- 常用工具链和虚拟环境-WSL
- [Arduino] Reborn Arduino Monk (2)----Arduino Language
- 【UE4】搭建局域网内VR直播 UE4.27
- Summary of some interviews
- PHICOMM(斐讯)N1盒子 - recovery模式救砖卡登录页LOGO卡1%卡4%卡26%
- 复杂多层布局的初级智能文本提示器
- 关于提高企业网络安全意识
猜你喜欢

【面经】被虐了之后,我翻烂了equals源码,总结如下

Topic Modeling of Short Texts: A Pseudo-Document View

DJI内推码(2022年8月2日更新)

软件定义网络实验之SDN网络简单管理及开发

5.软件测试-----自动化测试

【Swoole系列3.3】单进程管理Process

易购数码类电商商城网页设计与实现项目源码

【云原生】灰度发布、蓝绿发布、滚动发布、灰度发布解释

The LVS load balancing cluster and the deployment of the LVS - NAT experiment

LVS负载均衡群集及部署LVS-NAT实验
随机推荐
lombok 下的@Builder和@EqualsAndHashCode(callSuper = true)注解
【云原生】服务行业案例-不可预测的并发场景解决方案
The LVS load balancing cluster and the deployment of the LVS - NAT experiment
torchvision.datasets.ImageFolder使用详解
[Example构造方法增加notNull参数,默认false,允许值为null,值为null的时候不加入到条件中
选中按钮上色
MySQL里获取当前周、月、季的第一天/最后一天
YYGH-BUG-06
豆瓣评分9.3的好书,文末给大家抽奖送几本!
Excel 如何比较两列字符串是否相同?
10-security登录
扩展卡尔曼滤波【转】
LVS-NAT模式【案例实验】
numpy PIL tensor之间的相互转换
Jenkins2.328+sonarqube7.9 实现代码自动化检测
apache-activemq-5.14.1
.NET in-depth analysis of the LINQ framework (four: IQueryable, IQueryProvider interface details)
7-Redis工具类
Kook机器人开发日志01
Violent recursion to dynamic programming 06 (the sword refers to Offer II 095. Longest common subsequence)