如何更改QTableView的标题背景颜色 [英] How to change the header background color of a QTableView

查看:547
本文介绍了如何更改QTableView的标题背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我目前尝试的内容.标题文本可以正确更改颜色,但背景不会更改为默认值.

The following is what I've currently tried. The header text changes color correctly but the background will not change from the default.

template<typename T>
inline QVariant TableModel<T>::headerData(int section, Qt::Orientation orientation, int role) const
{
    //...
    else if(role == Qt::BackgroundRole) {
        return QBrush(m_display.headerBackground);
    }
    //...
}

如何设置背景颜色?

推荐答案

您可以在QTableView上设置样式表

You can set the style sheet on the QTableView

ui->tableView->setStyleSheet("QHeaderView::section { background-color:red }");

有关更多信息,请参见 http://doc.qt.io/qt- 4.8/stylesheet-examples.html

for more info see http://doc.qt.io/qt-4.8/stylesheet-examples.html

这篇关于如何更改QTableView的标题背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆