标题:QT应用程序界面字符颜色、背景颜色设置问题(UI,setStyleSheet)
作者:呆哥哥
日期:2019-10-17 20:05
内容:
上图中的界面设置为深色背景,比较简单。
下面图中的表头的背景设置可用以下两句来完成:
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等,另一个区域是横向表头与垂直表头相交叉的区域)。万能的网呀,请把大神带来帮帮我吧!!!
#1 [呆哥哥 10-17 20:19]
对了,环境是VS2017C++。请大神们指点一下,试了N多语句,都不起作用!
#2 [liudianwu 10-18 08:25]
上面那个是QTabBar
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;
}下面这个是表格的左上角按钮
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
强烈推荐关注里边的[url=h ..
#3 回 liudianwu 的帖子 [呆哥哥 10-18 20:40]
liudianwu:上面那个是QTabBar
QTabBar::tab{
border:1px solid #353535;
color:#F0F0F0;
margin:0px;
.......(2019-10-18 08:25)
非常感谢回复。我把上面两部分代码测试了一下。第二部分的代码能起作用。可以顺利设置横向和纵向表头交叉处的颜色。
但第一部分代码,我把它放到“编辑样式表”里,没起作用!请问是没弄对吗?应该放哪才能起作用?谢谢!
#4 [呆哥哥 10-18 22:13]
又反复用总版主回复的代码测试来测试去,其中有一次Tab1和Tab2标签的颜色变了,但同时周围的颜色却又恢复成灰色(“周围”指的是工具栏区域和状态栏区域)。回过头又变动了一下,Tab1和Tab2标签的颜色就再也变不了,始终是灰色了 。
#5 [呆哥哥 10-20 11:50]
看了“Qt样式表武林秘籍.pdf”,又看了“Qt样式表葵花宝典.pdf”,可真是高深呀。然而,我需要的Tab背景色暗自岿然不动!!!