程序员开发实例大全宝库

网站首页 > 编程文章 正文

Qt QTableView 样式参考(土壤污染风险管控标识牌参考样式)

zazugpt 2024-08-12 03:06:24 编程文章 23 ℃ 0 评论

Qt QTableView 样式参考

QTableView样式分多个区域

整体样式

QTableView {
    color: white;                                       /*表格内文字颜色*/
    gridline-color: black;                              /*表格内框颜色*/
    background-color: rgb(108, 108, 108);               /*表格内背景色*/
    alternate-background-color: rgb(64, 64, 64);
    selection-color: white;                             /*选中区域的文字颜色*/
    selection-background-color: rgb(77, 77, 77);        /*选中区域的背景色*/
    border: 2px groove gray;
    border-radius: 0px;
    padding: 2px 4px;
}

奇偶行区分颜色样式

cpp:
view->setAlternatingRowColors(true);

qss:
QTableView{
    background-color: rgb(250, 250, 115);
    alternate-background-color: rgb(141, 163, 215);
}

水平/垂直表头
设置表头样式

【领QT开发教程学习资料,点击下方链接免费领取↓↓,先码住不迷路~】

点击→领取「链接」

QHeaderView {
    color: white;
    font: bold 10pt;
    background-color: rgb(108, 108, 108);/*设置表头空白区域背景色*/
    border: 0px solid rgb(144, 144, 144);
    border:0px solid rgb(191,191,191);
    border-left-color: rgba(255, 255, 255, 0);
    border-top-color: rgba(255, 255, 255, 0);
    border-radius:0px;
    min-height:29px;
}

为垂直及水平表头分别设置样式
表头为QHeaderView,水平表头和垂直表头都是QHeaderView,需要设置QTableView两个表头的ObjectName进行区分

1 view->horizontalHeader()->setObjectName("hHeader");
2 view->verticalHeader()->setObjectName("vHeader");

样式中根据不同对象名称进行样式设置

 1 QHeaderView#hHeader::section {
 2     background-color:darkcyan;
 3     color: red;padding-left: 4px;
 4     border: 1px solid #6c6c6c;
 5     height:40;
 6 }
 7 QHeaderView#vHeader::section {
 8     background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #616161, stop: 0.5 yellow,stop: 0.6 green, stop:1 cyan);
 9     color: white;padding-left: 4px;border: 1px solid #6c6c6c;
10     width:30;
11 }

左上角空白区域
设置完QTableView头部后,左上角区域为白色,需要为左上角区域设置样式

 1 /*QTableView 左上角样式*/
 2 QTableView QTableCornerButton::section {
 3    /*  background: red;
 4     border: 2px outset red;*/
 5     color: red;
 6     background-color: rgb(64, 64, 64);
 7     border: 5px solid #f6f7fa;
 8     border-radius:0px;
 9     border-color: rgb(64, 64, 64);
10  }

表头内容区域

1 QHeaderView::section {
2     color: white;
3     background-color: rgb(64, 64, 64);
4     border: 5px solid #f6f7fa;
5     border-radius:0px;
6     border-color: rgb(64, 64, 64);
7 } 

全部样式代码:

 1 /*QTableView 左上角样式*/
 2 QTableView QTableCornerButton::section {
 3    /*  background: red;
 4     border: 2px outset red;*/
 5     color: red;
 6     background-color: rgb(64, 64, 64);
 7     border: 5px solid #f6f7fa;
 8     border-radius:0px;
 9     border-color: rgb(64, 64, 64);
10  }
11 
12  QTableView {
13     color: white;                                       /*表格内文字颜色*/
14     gridline-color: black;                              /*表格内框颜色*/
15     background-color: rgb(108, 108, 108);               /*表格内背景色*/
16     alternate-background-color: rgb(64, 64, 64);
17     selection-color: white;                             /*选中区域的文字颜色*/
18     selection-background-color: rgb(77, 77, 77);        /*选中区域的背景色*/
19     border: 2px groove gray;
20     border-radius: 0px;
21     padding: 2px 4px;
22 }
23 
24 QHeaderView {
25     color: white;
26     font: bold 10pt;
27     background-color: rgb(108, 108, 108);
28     border: 0px solid rgb(144, 144, 144);
29     border:0px solid rgb(191,191,191);
30     border-left-color: rgba(255, 255, 255, 0);
31     border-top-color: rgba(255, 255, 255, 0);
32     border-radius:0px;
33     min-height:29px;
34 }
35 
36 QHeaderView::section {
37     color: white;
38     background-color: rgb(64, 64, 64);
39     border: 5px solid #f6f7fa;
40     border-radius:0px;
41     border-color: rgb(64, 64, 64);
42 } 

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表