在自定義模型的headerData()函式中通過判斷role==Qt::BackgroundRole修改表頭的背景顏色,但是不起作用,代碼如下,其中通過相同的方式修改前景色,即文本顏色是可行的,請問該如何使背景色生效?
QVariant headerData(int section, Qt::Orientation orientation,int role) const
{
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
{
if(section < HeaderData.size())
return HeaderData.at(section);
else
return QVariant();
}
if(role == Qt::BackgroundRole)
return QBrush(QColor(Qt::green));
if(role == Qt::ForegroundRole)
return QBrush(QColor(Qt::red));
return QVariant();
}
uj5u.com熱心網友回復:
有沒有寫代理或者css樣式表了呀uj5u.com熱心網友回復:
沒有寫代理,也沒有用樣式表uj5u.com熱心網友回復:
今天也在用qtableview貌似只能改表格里面的“內容”,背景或者border都不行,得用樣式表或者代理(給headerview設定代理)實作轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/117145.html
標籤:Qt
