QT-qss样式化QTableView,QTreeView,QTableWidget

qss样式化QTableView,QTreeView,QTableWidget

QHeaderView                    // QTableWidget 标题头整个区域
{
    background:transparent;        // 整个标题头区域背景色
}

QHeaderView::section           // 标题头 每个单独的标题区域
{
    font-size:14px;                // 每个标题的字体大小
    font-family:"Microsoft YaHei"; // 每个标题的字体类型
    color:#FFFFFF;                 // 每个标题的字体颜色
 
    background:#60669B;            // 每个标题区域的背景色
    border:none;                   // 每个标题区域的边框
    text-align:left;               // 每个标题的对齐方式(貌似不能用)。建议使用tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter)
 
 
    min-height:49px;               // 标题区域的高度
    max-height:49px;               //
 
    margin-left:0px;               // 每个标题区域的margin
    padding-left:0px;              // 每个标题区域的padding
}
 
QTableWidget                   // 整个表格控件
{
    background:#FFFFFF;            // 整个表格控件 背景色
    border:none;                   // 整个表格控件 边框
 
    font-size:12px;                // 所有字体大小
    font-family:"Microsoft YaHei"; // 所有字体 family
    color:#666666;                 // 所有字体颜色
}
 
QTableWidget::item                // 每个单元格
{
    border-bottom:1px solid #EEF1F7 ; // 只显示每个单元格下边框
}
 
QTableWidget::item::selected      // 每个单元格被选中状态
{
    color:red;                        // 每个单元格被选中时 字体颜色
    background:#EFF4FF;               // 每个单元格被选中时 背景颜色
}
 
QScrollBar::handle:vertical        // 垂直滚动条 handle
{
    background: rgba(255,255,255,20%); // 垂直滚动条 handle 的背景色
    border: 0px solid grey;            // 垂直滚动条 handle 边框
    border-radius:3px;                 // 垂直滚动条 handle 圆角
    width: 8px;                        // 垂直滚动条 handle 宽度
}

QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical // 垂直滚动条  handle上、下区域(未被handle占用的区域)
{
    background:rgba(255,255,255,10%);                            // 垂直滚动条 handle上、下区域的背景色
}

QScollBar::add-line:vertical, QScrollBar::sub-line:vertical  // 垂直滚动条 最顶端与最低端的区域
{
    background:transparent;                                      // 垂直滚动条 最顶端与最低端区域的背景色
}

// 设置单元格高度:
tableWidget->verticalHeader()->setDefaultSectionSize();

// 设置标题对齐方式
tableWidget->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter);

// 设置选择单元格 不出现虚线框(虚框)
tableWidget->setFocusPolicy(Qt::NoFocus);
```cpp
/*tablewidget 样式*/
QTableView,QTableWidget {
    selection-background-color:#44c767;
    background-color:white;     /*整个表格的背景色,这里为白色*/
    border:1px solid #E0DDDC;   /*边框为1像素,灰色*/
    gridline-color:lightgray;   /*这个是表格的格子线的颜色,为亮灰*/
}
 
/*这里是表格表头样式*/
QHeaderView::section {
    background-color:white;     /*背景色 白色*/
    border:0px solid #E0DDDC;   /*先把边框宽度设为0,即隐藏所有表头边框*/
    border-bottom:1px solid #E0DDDC;/*然后只显示下边框,因为上边框和左右边框是整个Table的边框,都显示会有2px的边框宽度*/
    height:20px;                /*表头高度*/
}

QTableView{
    color: rgb(0, 0, 0);
    border: 1px solid #C07010;          /*边框颜色*/
    gridline-color:#C07010;             /*grid线颜色*/
    background-color: rgb(20, 20, 20);
    alternate-background-color: rgb(200, 200, 200); /*行交替颜色*/
    selection-background-color: rgb(130, 190, 100); /*选中行背景颜色*/
}
 
QTableView::item:!alternate:!selected{
    background-color: rgb(220, 220, 220);    /*交替行的另一颜色*/
}

QToolButton{
   min-width:80px;
   min-height:32px;
}
QToolButton{
color:rgb(255, 255, 255);
min-height:20;
border-style:solid;
border-top-left-radius:2px;
border-top-right-radius:2px;
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 rgb(226,236,241), 
                            stop: 0.3 rgb(160,160,160),
                              stop: 1 rgb(140,140,140));
border:1px;
border-radius:5px;padding:2px 4px;/*border-radius控制圆角大小*/
}
QToolButton:hover{  /*鼠标放上后*/
color:rgb(255, 255, 255);
min-height:20;
border-style:solid;
border-top-left-radius:2px;
border-top-right-radius:2px;
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 rgb(226,236,241), 
                            stop: 0.3 rgb(160,160,160),
                              stop: 1 rgb(120,120,120));
border:1px;
border-radius:5px;padding:2px 4px;
}
QToolButton:pressed{ /*按下按钮后*/
color:rgb(255, 255, 255);
min-height:20;
border-style:solid;
border-top-left-radius:2px;
border-top-right-radius:2px;
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 rgb(226,236,241), 
                            stop: 0.3 rgb(190,190,190),
                              stop: 1 rgb(160,160,160));
border:1px;
border-radius:5px;padding:2px 4px;
}
QToolButton:checked{    /*选中后*/
color:rgb(255, 255, 255);
min-height:20;
border-style:solid;
border-top-left-radius:2px;
border-top-right-radius:2px;
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop:0 rgb(226,236,241), 
                            stop: 0.3 rgb(190,190,190),
                              stop: 1 rgb(160,160,160));
border:1px;
border-radius:5px;padding:2px 4px;
}
  • 2
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值