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

来源:互联网 发布:java 校验时间格式 编辑:程序博客网 时间:2024/06/07 21:42

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

原创粉丝点击