QTreeWidget基本属性操作

文章目录

一、背景设置

1、添加背景颜色之前与之后的对比

1.2背景设置的两种方式

通过QT设计界面中的改变样式表进行属性配置,如图所示

在代码中:

cpp 复制代码
setStyleSheet("QHeaderView::section{ background-color: rgb(170, 170, 127);}");

2、边框设置

头部除了背景色可以设置还有很多的参数可以设置

例如:添加背景图、修改渐变色、字体以及边框等

头部边框属性设置,效果如图所示

实现方法:

cpp 复制代码
#Qss示例:对边框的线宽以及背景颜色进行了配置
QHeaderView::section
{ 
border: 3px solid qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 178, 102, 255), stop:0.55 rgba(235, 148, 61, 255), stop:0.98 rgba(0, 0, 0, 255), stop:1 rgba(0, 0, 0, 0));
}

border 边框属性设置,基本参数(来源网络)

2.1、演示以上参数的实际效果

2.1.1、无边框、虚线、实线边框演示

cpp 复制代码
QHeaderView::section
{ 
border: none;

}

右边设置的无边框

cpp 复制代码
//Qss:虚线边框:
QHeaderView::section
{ 
border-width:2px;
border-style:dashed;
border-color: rgb(170, 170, 0);

}
//线宽不要使用默认值,显示不出虚线的效果,还可以对单个的边进行设置
QHeaderView::section
{ 
border-width:2px;
border-top-style:dotted;
border-right-style:solid;
border-bottom-style:dashed;
border-left-style:solid;

}

效果图:

cpp 复制代码
//Qss:双边框:
QHeaderView::section
{ 
border-style:double;
border-width:5px;
}

效果图(双边框与虚线边框的对比):

2.1.2、边框的3D效果

cpp 复制代码
//groove  这里背景设置了一个渐变色
QHeaderView::section
{ 
border: 8px groove qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 178, 102, 255), stop:0.55 rgba(235, 148, 61, 255), stop:0.98 rgba(0, 0, 0, 255), stop:1 rgba(0, 0, 0, 0));

}

效果图(与虚线边框对比):

cpp 复制代码
//ridge
QHeaderView::section
{ 

border: 8px ridge qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgba(255, 178, 102, 255), stop:0.55 rgba(235, 148, 61, 255), stop:0.98 rgba(0, 0, 0, 255), stop:1 rgba(0, 0, 0, 0));
}

效果图:

cpp 复制代码
//inset
//Qss:
QHeaderView::section
{ 
border: 8px inset rgb(106, 106, 106);
}

效果图(右边ridge 与左边inset 对比):

cpp 复制代码
//outset
//Qss
QHeaderView::section
{ 
border: 8px outset rgb(106, 106, 106);
}

效果图(右边outset 左边inset对比):

相关推荐
kupeThinkPoem1 小时前
QJsonObject能否嵌套查找?
qt·json
Henry Zhu1232 小时前
Qt样式系统详解(下)
qt
hqwest3 小时前
码上通QT实战10--监控页面02-绘制温度盘
开发语言·qt·自定义控件·qwidget·提升部件·qt绘图
cn_mengbei3 小时前
鸿蒙PC开发实战:Qt环境搭建保姆级教程与常见问题避坑指南(HarmonyOS 4.0+DevEco Studio 3.1最新版)
qt·华为·harmonyos
非凡ghost3 小时前
MPC-QT视频播放器(基于Qt框架播放器)
开发语言·windows·qt·音视频·软件需求
cn_mengbei4 小时前
从零到一:基于Qt on HarmonyOS的鸿蒙PC原生应用开发实战与性能优化指南
qt·性能优化·harmonyos
IOT-Power6 小时前
QT 对话框(QDialog)中 accept、reject、exec、open的使用
开发语言·qt
_OP_CHEN6 小时前
【从零开始的Qt开发指南】(十九)Qt 文件操作:从 I/O 设备到文件信息,一站式掌握跨平台文件处理
开发语言·c++·qt·前端开发·文件操作·gui开发·qt文件
cn_mengbei7 小时前
鸿蒙PC开发指南:从零配置Qt环境到实战部署完整流程
qt·华为·harmonyos
GREGGXU7 小时前
Could not load the Qt platform plugin “xcb“ in ““ even though it was found.
linux·qt