加载中…
个人资料
一去二三里
一去二三里
  • 博客等级:
  • 博客积分:0
  • 博客访问:2,832,353
  • 关注人气:909
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

Qt之QTreeView(三)

(2014-12-23 18:16:16)
标签:

qt

qtreeview

qtableview

qstyleditemdelegate

qabstractitemmodel

分类: Qt
    通过Qt之QTreeView(一)即可正常加载数据,Qt之QTreeView(二)即可自定义图标、按钮,注册事件等。。。那么,到这里,基本的使用已经完成,为了界面的美观性,这里提供三种样式以供选择。

样式一:

QString styleOne = "QTreeView{\
        border: 1px solid lightgray;\
    }\
    QTreeView::item {\
            height: 40px;\
            border-radius: 2px;\
            border: 1px solid transparent;\
            background: transparent;\
            color: black;\
    }\
    QTreeView::item:hover {\
            border: 1px solid rgb(185, 215, 250);\
    }\
    QTreeView::item:selected {\
            border: 1px solid rgb(170, 190, 230);\
            background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgb(230, 240, 250), stop: 0.5 rgb(220, 235, 255), stop: 1.0 rgb(210, 230, 255));\
    }\
    QTreeView::branch:open:has-children {\
            image: url(./Resources/Images/branchOpen.png);\
    }\
    QTreeView::branch:closed:has-children {\
            image: url(./Resources/Images/branchClose.png);\
    }";
效果如下:
Qt之QTreeView(三)

样式二:

QString styleTwo = "QTreeView{\
            border: 1px solid lightgray;\
    }\
    QTreeView::item {\
            height: 40px;\
            border-radius: 2px;\
            border: 1px solid transparent;\
            background: transparent;\
            color: black;\
    }\
    QTreeView::item:has-children {\
            border: none;\
            border-bottom: 1px solid lightgray;\
    }\
    QTreeView::item:hover {\
            border: 1px solid rgb(170, 190, 230);\
            background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgb(230, 240, 250), stop: 0.5 rgb(220, 235, 255), stop: 1.0 rgb(210, 230, 255));\
    }\
    QTreeView::item:selected {\
            border: 1px solid rgb(170, 190, 230);\
            background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 rgb(230, 240, 250), stop: 0.5 rgb(220, 235, 255), stop: 1.0 rgb(210, 230, 255));\
    }\
    QTreeView::branch:open:has-children {\
            image: url(./Resources/Images/branchOpen2.png);\
    }\
    QTreeView::branch:closed:has-children {\
            image: url(./Resources/Images/branchClose2.png);\
    }";

效果如下:
Qt之QTreeView(三)

样式三:

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(./Resources/Images/branchOpen.png);\
    }\
    QTreeView::branch:closed:has-children {\
            image: url(./Resources/Images/branchClose.png);\
    }";
效果如下:
Qt之QTreeView(三)

   以上主要通过对边框、背景、文本、滑过、选中来设置不同的样式,仅供参考。如要实现自己想要的效果,那么可以好好研究下QSS!
    好了,介绍了这么多,还是把源码奉上,地址:自定义QTreeView(详解)


注:
    技术在于交流、沟通,转载请注明出处并保持作品的完整性。

0

阅读 收藏 喜欢 打印举报/Report
后一篇:Qt之滚动字幕
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有