您的位置:首页 > 编程语言 > Qt开发

Qt treeView的展开折叠按钮的设置

2017-12-08 15:34 1006 查看
Qt tireeView自带的展开折叠按钮是三角形的,实在是太难看了,想要换个风格,在网上找了半天,只是找到 treeView->setStyleSheet(styleThree)这个函数,能解释具体怎么用的文章少之又少,不过最终还是让我找到了一篇!


Qt利用setStyleSheet设置样式

作者:Joven_xxx

Qt中设置按钮或QWidget的外观是,可以使用QT Style Sheets来进行设置,非常方便。
可以用setStyleSheet("font: bold; font-size:20px; color: rgb(241, 70, 62); background-color: green");来进行设置,其他的样式介绍如下:
font: bold;是否粗体显示
border-image:"";用来设定边框的背景图片。
border-radius:5px;用来设定边框的弧度。可以设定圆角的按钮
border-width: 1px;边框大小

font-family:"";来设定字体所属家族,
font-size:20px;来设定字体大小
font-style:"";来设定字体样式
font-weight:20px;来设定字体深浅
 background-color: green;设置背景颜色
background:transparent;设置背景为透明
color:rgb(241, 70, 62);设置前景颜色
selection-color:rgb(241, 70, 62);用来设定选中时候的颜色

可以使用border-top,border-right,border-bottom,border-left分别设定按钮的上下左右边框,
同样有border-left-color, border-left-style, border-left-width.等分别来设定他们的颜色,样式和宽度

将网上一去二三里的格式拔了过来,表示很好用

QString styleThree = "QTreeView{\

border: 1px solid lightgray;\

}\

QTreeView::item {\

height: 25px;\

border: none;\

background: transparent;\

color: black;\

}\

QTreeView::item:hover {\

background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgb(255, 220, 130), stop: 0.5 rgb(255, 220, 130), stop: 1.0 rgb(255, 230, 150));\

}\

QTreeView::item:selected {\

background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgb(255, 200, 100), stop: 0.5 rgb(255, 230, 150), stop: 1.0 rgb(255, 240, 150));\

}\

QTreeView::branch:open:has-children {\

image: url(展开时图片path);\

}\

QTreeView::branch:closed:has-children {\

image: url(折叠时图片path);\

}";

附上他的详细讲解http://blog.csdn.net/liang19890820/article/details/52606662
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: