zoukankan      html  css  js  c++  java
  • QT修改默认的滚动条样式

    这几天写一个类似于悬浮窗的小程序,可是qt自带的滚动条实在难看,经过多番查找终于找到一个类似于qq聊天窗口的滚动条,废话不说上代码。希望能帮到大家

    1.写入到文件中,新建个xx.qss,然后复制一下内容:

    // 设置垂直滚动条基本样式
    QScrollBar:vertical
    {
        8px;
        background:rgba(0,0,0,0%);
        margin:0px,0px,0px,0px;
        padding-top:9px;   // 留出9px给上面和下面的箭头
        padding-bottom:9px;
    }
    QScrollBar::handle:vertical
    {
        8px;
        background:rgba(0,0,0,25%);
        border-radius:4px;   // 滚动条两端变成椭圆
        min-height:20;
    }
    QScrollBar::handle:vertical:hover
    {
        8px;
        background:rgba(0,0,0,50%);   // 鼠标放到滚动条上的时候,颜色变深
        border-radius:4px;
        min-height:20;
    }
    QScrollBar::add-line:vertical   // 这个应该是设置下箭头的,3.png就是箭头
    {
        height:9px;8px;
        border-image:url(:/images/a/3.png);
        subcontrol-position:bottom;
    }
    QScrollBar::sub-line:vertical   // 设置上箭头
    {
        height:9px;8px;
        border-image:url(:/images/a/1.png);
        subcontrol-position:top;
    }
    QScrollBar::add-line:vertical:hover   // 当鼠标放到下箭头上的时候
    {
        height:9px;8px;
        border-image:url(:/images/a/4.png);
        subcontrol-position:bottom;
    }
    QScrollBar::sub-line:vertical:hover  // 当鼠标放到下箭头上的时候
    {
        height:9px;8px;
        border-image:url(:/images/a/2.png);
        subcontrol-position:top;
    }
    QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical   // 当滚动条滚动的时候,上面的部分和下面的部分
    {
        background:rgba(0,0,0,10%);
        border-radius:4px;
    }
    接着在程序中读取文件:

    QFile file(":/scrollbar.qss");
    file.open(QFile::ReadOnly);
    listWidget->verticalScrollBar()->setStyleSheet(file.readAll());
     2.直接在程序中设置,简单
    listWidget->verticalScrollBar()->setStyleSheet("QScrollBar:vertical"
                                                       "{"
                                                       "8px;"
                                                       "background:rgba(0,0,0,0%);"
                                                       "margin:0px,0px,0px,0px;"
                                                       "padding-top:9px;"
                                                       "padding-bottom:9px;"
                                                       "}"
                                                       "QScrollBar::handle:vertical"
                                                       "{"
                                                       "8px;"
                                                       "background:rgba(0,0,0,25%);"
                                                       " border-radius:4px;"
                                                       "min-height:20;"
                                                       "}"
                                                       "QScrollBar::handle:vertical:hover"
                                                       "{"
                                                       "8px;"
                                                       "background:rgba(0,0,0,50%);"
                                                       " border-radius:4px;"
                                                       "min-height:20;"
                                                       "}"
                                                       "QScrollBar::add-line:vertical"
                                                       "{"
                                                       "height:9px;8px;"
                                                       "border-image:url(:/images/a/3.png);"
                                                       "subcontrol-position:bottom;"
                                                       "}"
                                                       "QScrollBar::sub-line:vertical"
                                                       "{"
                                                       "height:9px;8px;"
                                                       "border-image:url(:/images/a/1.png);"
                                                       "subcontrol-position:top;"
                                                       "}"
                                                       "QScrollBar::add-line:vertical:hover"
                                                       "{"
                                                       "height:9px;8px;"
                                                       "border-image:url(:/images/a/4.png);"
                                                       "subcontrol-position:bottom;"
                                                       "}"
                                                       "QScrollBar::sub-line:vertical:hover"
                                                       "{"
                                                       "height:9px;8px;"
                                                       "border-image:url(:/images/a/2.png);"
                                                       "subcontrol-position:top;"
                                                       "}"
                                                       "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
                                                       "{"
                                                       "background:rgba(0,0,0,10%);"
                                                       "border-radius:4px;"
                                                       "}"
                                                       );


    
    
  • 相关阅读:
    关于在Websphere下程序找不到jar包内.properties文件的问题
    MysqL的root用户不允许远程连接
    ajax提交表单数据到controller
    js表单验证
    jq删除标签中的元素
    点击超链接触发js事件
    spring的特点
    mysql每个jar包的作用
    抽象工厂举例
    简单的省市联动
  • 原文地址:https://www.cnblogs.com/huangpeng1990/p/4364374.html
Copyright © 2011-2022 走看看