QSS实践汇总(4)——QTableWidget、QTableView样式(风格)

一、特别说明

QHeaderView设置不生效。以下可以解决问题,但不知道原因,若有小伙伴知道原因或还有其他更好的办法请留言,感谢感谢!

使用QApplication设置styleSheet

(1)在main函数中设置

        QApplication a(argc,argv);

        a.seetStyleSheet(“QTableWidget QHeaderView::section{background:transparent;color:rgb(19,154,230),min-height:30px;”)

(2)加载QSS文件时先使用QApplication加载

QString strQss;

QFile file;

QString strDirPath = QApplication::applicationDirPath();

QString strPath = strDirPath + QString("/../temp/testQss/userMgmt.qss");

file.setFileName(strPath);

if (file.open(QIODevice::ReadOnly))

{

strQss = QString::fromLocal8Bit(file.readAll());

strQss = strQss.arg(strDirPath);

QApplication* pApp = (QApplication*)(QApplication::instance());

pApp->setStyleSheet(strQss); // 仅调用this->setStyleSheet(strQss);QTableWidget的表头样式不生效,原因未知

this->setStyleSheet(strQss);// 仅调用pApp->setStyleSheet(strQss); 部分QWidget QPushButton样式不生效,原因未知

file.close();

}

二、QTabelWidget风格设置

 

// 表头

QTableWidget QHeaderView{

border-bottom:1px solid rgb(35,95,155);

}

// 表头项

QTableWidget QHeaderView::section{

background:transparent;

color:rgb(19,154,230);

min-height:30px;

font: 14px "NSimSun";

}

// 列表

QTableWidget{

outline:none;

border: 1px solid rgb(9,109,165);

border-top:none;

border-bottom-left-radius:4px;

border-bottom-right-radius:4px;

alternate-background-color:rgba(35,95,155,64); // 奇数行颜色

selection-background-color:rgba(26,131,208,255); // 选中行颜色

gridline-color:rgb(35,95,155); // 网格线颜色

color:rgb(230,230,230);

font: 16px "NSimSun";

}

  • 0
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值