设置QAbstractTableModel表头背景色的问题

chengshiding 2013-05-20 02:19:11

QVariant TableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(role ==Qt::BackgroundRole)
{
//if(orientation == Qt::Vertical)
if (orientation == Qt::Horizontal)
switch (section)
{
case 0:
return QBrush(QColor(Qt::blue));
case 1:
return QVariant(QColor(Qt::blue));
default:
return QAbstractTableModel::headerData(section,orientation,role);
}


可以设置headerData的字体颜色,字体加粗。data的字体颜色,背景色,字体风格等。
但是就是不能设置headerData的背景色。
OS是xp
求解!
...全文
621 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chengshiding 2013-06-03
  • 打赏
  • 举报
回复
求高手解决! 3QQQQQQQQQQQQ
chengshiding 2013-05-30
  • 打赏
  • 举报
回复
setStyleSheet设置可以起作用,调色板等其他方式不起作用。
微雨流光 2013-05-27
  • 打赏
  • 举报
回复
setStyleSheet("\ QTableWidget{\ color: white;\ gridline-color: white;\ background: #2c2c2d;\ alternate-background-color: #3a3a3c;\ selection-color: white;\ selection-background-color: #595a5c;\ border: 0px solid;\ }\ 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::section {\ color: white;\ background-color: rgb(67, 67, 69);\ border: 1px solid #f6f7fa;\ border-radius:0px;\ border-color: rgb(67, 67, 69);\ }\ "); 试试这个QTableWidget的 类似吧应该
chengshiding 2013-05-27
  • 打赏
  • 举报
回复
大家不要沉默啊
chengshiding 2013-05-23
  • 打赏
  • 举报
回复
求高人 指点
addfourliu 2013-05-20
  • 打赏
  • 举报
回复
嗯啊 , 那你要再研究研究看啦。。。
chengshiding 2013-05-20
  • 打赏
  • 举报
回复
引用 1 楼 addfourliu 的回复:
首先取出TableHeader的style, 然后在setStyleSheet中利用QHeaderView来设置背景色 参照: tbl_widget->horizontalHeader()->setStyleSheet( "QHeaderView::section{background-color: transparent}" );
这个方法对于我要设置特定的行的列表头的背景色不是很好用的。因为这个设置经常要改变
addfourliu 2013-05-20
  • 打赏
  • 举报
回复
首先取出TableHeader的style, 然后在setStyleSheet中利用QHeaderView来设置背景色 参照: tbl_widget->horizontalHeader()->setStyleSheet( "QHeaderView::section{background-color: transparent}" );

16,203

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧