设置QAbstractTableModel表头背景色的问题
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
求解! --------------------编程问答-------------------- 首先取出TableHeader的style, 然后在setStyleSheet中利用QHeaderView来设置背景色
参照:
tbl_widget->horizontalHeader()->setStyleSheet( "QHeaderView::section{background-color:
transparent}" );
--------------------编程问答--------------------
这个方法对于我要设置特定的行的列表头的背景色不是很好用的。因为这个设置经常要改变 --------------------编程问答-------------------- 嗯啊 , 那你要再研究研究看啦。。。 --------------------编程问答-------------------- 求高人 指点 --------------------编程问答-------------------- 大家不要沉默啊 --------------------编程问答-------------------- 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的 类似吧应该 --------------------编程问答-------------------- setStyleSheet设置可以起作用,调色板等其他方式不起作用。 --------------------编程问答-------------------- 求高手解决!
3QQQQQQQQQQQQ
补充:移动开发 , Qt