查看完整版本: [-- QT应用程序界面字符颜色、背景颜色设置问题(UI,setStyleSheet) --]

QTCN开发网 -> Qt基础编程 -> QT应用程序界面字符颜色、背景颜色设置问题(UI,setStyleSheet) [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

呆哥哥 2019-10-17 20:05

QT应用程序界面字符颜色、背景颜色设置问题(UI,setStyleSheet)

[attachment=20957]


上图中的界面设置为深色背景,比较简单。
下面图中的表头的背景设置可用以下两句来完成:
ui.HQTable->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color:rgb(40,143,218);color: white;};");//横向表头
ui.HQTable->verticalHeader()->setStyleSheet("QHeaderView::section{background-color:rgb(40,143,218);color: white;};"); //设置垂直表头
然而,下面图中两个红圈内的区域的背景设置,要怎么弄?(一个区域是所谓的“标签”即TAB1和TAB2等,另一个区域是横向表头与垂直表头相交叉的区域)。万能的网呀,请把大神带来帮帮我吧!!!
[attachment=20958]


呆哥哥 2019-10-17 20:19
对了,环境是VS2017C++。请大神们指点一下,试了N多语句,都不起作用!

liudianwu 2019-10-18 08:25
上面那个是QTabBar
  1. QTabBar::tab{
    border:1px solid #353535;
    color:#F0F0F0;
    margin:0px;
    background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #636363,stop:1 #575757);
    }

    QTabBar::tab:selected,QTabBar::tab:hover{
    border-style:solid;
    border-color:#00BB9E;
    background:#464646;
    }

    QTabBar::tab:top,QTabBar::tab:bottom{
    padding:3px 8px 3px 8px;
    }

    QTabBar::tab:left,QTabBar::tab:right{
    padding:8px 3px 8px 3px;
    }

    QTabBar::tab:top:selected,QTabBar::tab:top:hover{
    border-width:2px 0px 0px 0px;
    }

    QTabBar::tab:right:selected,QTabBar::tab:right:hover{
    border-width:0px 0px 0px 2px;
    }

    QTabBar::tab:bottom:selected,QTabBar::tab:bottom:hover{
    border-width:0px 0px 2px 0px;
    }

    QTabBar::tab:left:selected,QTabBar::tab:left:hover{
    border-width:0px 2px 0px 0px;
    }

    QTabBar::tab:first:top:selected,QTabBar::tab:first:top:hover,QTabBar::tab:first:bottom:selected,QTabBar::tab:first:bottom:hover{
    border-left-width:1px;
    border-left-color:#353535;
    }

    QTabBar::tab:first:left:selected,QTabBar::tab:first:left:hover,QTabBar::tab:first:right:selected,QTabBar::tab:first:right:hover{
    border-top-width:1px;
    border-top-color:#353535;
    }

    QTabBar::tab:last:top:selected,QTabBar::tab:last:top:hover,QTabBar::tab:last:bottom:selected,QTabBar::tab:last:bottom:hover{
    border-right-width:1px;
    border-right-color:#353535;
    }

    QTabBar::tab:last:left:selected,QTabBar::tab:last:left:hover,QTabBar::tab:last:right:selected,QTabBar::tab:last:right:hover{
    border-bottom-width:1px;
    border-bottom-color:#353535;
    }
下面这个是表格的左上角按钮
  1. QHeaderView::section,QTableCornerButton:section{
    padding:3px;
    margin:0px;
    color:#F0F0F0;
    border:1px solid #353535;
    border-left-width:0px;
    border-right-width:1px;
    border-top-width:0px;
    border-bottom-width:1px;
    background:qlineargradient(spread:pad,x1:0,y1:0,x2:0,y2:1,stop:0 #636363,stop:1 #575757);
    }
你需要来一份Qt样式表武林秘籍,请关注我的开源主页
https://gitee.com/feiyangqingyun
https://github.com/feiyangqingyun
强烈推荐关注里边的QWidgetDemo项目和Qt开发经验



呆哥哥 2019-10-18 20:40
liudianwu:上面那个是QTabBar
QTabBar::tab{
border:1px solid #353535;
color:#F0F0F0;
margin:0px;
....... (2019-10-18 08:25) 

非常感谢回复。我把上面两部分代码测试了一下。第二部分的代码能起作用。可以顺利设置横向和纵向表头交叉处的颜色。
但第一部分代码,我把它放到“编辑样式表”里,没起作用!请问是没弄对吗?应该放哪才能起作用?谢谢!

呆哥哥 2019-10-18 22:13
又反复用总版主回复的代码测试来测试去,其中有一次Tab1和Tab2标签的颜色变了,但同时周围的颜色却又恢复成灰色(“周围”指的是工具栏区域和状态栏区域)。回过头又变动了一下,Tab1和Tab2标签的颜色就再也变不了,始终是灰色了

呆哥哥 2019-10-20 11:50
看了“Qt样式表武林秘籍.pdf”,又看了“Qt样式表葵花宝典.pdf”,可真是高深呀。然而,我需要的Tab背景色暗自岿然不动!!!

wcrqpdb 2019-10-20 20:01
呆哥哥:看了“Qt样式表武林秘籍.pdf”,又看了“Qt样式表葵花宝典.pdf”,可真是高深呀。然而,我需要的Tab背景色暗自岿然不动!!! (2019-10-20 11:50) 

当然不行啦,最后那页你都未看,"欲练神功先必自宫"

呆哥哥 2019-10-21 15:16
wcrqpdb:当然不行啦,最后那页你都未看,"欲练神功先必自宫" (2019-10-20 20:01) 

若欲自宫,先求后宫。万一后宫不同意喃?^_^

呆哥哥 2019-10-21 15:30
liudianwu:
上面那个是QTabBar
[code]QTabBar::tab{
border:1px solid #353535;
color:#F0F0F0;
margin:0px;
.......

我又反复测试,还是未能如愿。目前是这样:用了你上面的代码后,Tab1、Tab2的背景颜色始终不变,效果如下:
[attachment=20964]
但这时,若去掉文本颜色和背景色的设置,则Tab1、Tab2的背景色起作用了,这时因去掉文本和背景的设置,默认文本为黑背景为白。效果如下:
[attachment=20965]
我也试过改变渐变属性等,但不行。请教:是不是因为背景设置为深色,则Tabx的背景与窗口背景反差太小而不能再设置为深色?还是什么原因?请指教!谢谢!@liudianwu  


查看完整版本: [-- QT应用程序界面字符颜色、背景颜色设置问题(UI,setStyleSheet) --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled