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对比):

相关推荐
kyle~4 小时前
python---PyInstaller(将Python脚本打包为可执行文件)
开发语言·前端·python·qt
ajassi20006 小时前
开源 C++ QT Widget 开发(十六)程序发布
linux·c++·qt·开源
DdduZe7 小时前
9.11作业
c++·qt
-凌凌漆-8 小时前
【Qt】【C++】虚析构函数及 virtual ~Base() = default
java·c++·qt
枫叶丹48 小时前
【Qt开发】显示类控件(二)-> QLCDNumber
开发语言·qt
搞全栈小苏17 小时前
基于Qt QML和C++的MQTT测试客户端(CMakeLists实现)
xml·c++·qt
qq_1728055920 小时前
GO RPC 教学文档
qt·rpc·golang
青铜发条21 小时前
【Qt】PyQt、原生QT、PySide6三者的多方面比较
开发语言·qt·pyqt
ajassi200021 小时前
开源 C++ QT Widget 开发(十四)多媒体--录音机
linux·c++·qt·开源
JCBP_1 天前
QT(3)
开发语言·汇编·c++·qt·算法