qt 5.11 发布后 QHeaderView 部分颜色停止在 linux 中显示。在 Windows 中正常工作。有没有人遇到过这个问题?
我将 QTableView 与 QHeaderView 一起使用。我可以覆盖paintSection 函数并做一些事情来解决这个问题吗?
如果您正在使用QAbstractTableModel
-QTableView
尝试覆盖
QVariant headerData(
int _section
, Qt::Orientation _orientation
, int _role /*= Qt::DisplayRole */
) const override;
如果这样做,您将能够在方法主体中写入以您想要的颜色绘制背景的机制。像这样的东西:
QVariant headerData(
int _section
, Qt::Orientation _orientation
, int _role
) const
{
if( _role == Qt::DisplayRole )
{
if( _orientation == Qt::Horizontal )
{
// TODO: Return there your header value.
}
}
else if( _role == Qt::BackgroundRole )
{
if( _orientation == Qt::Horizontal )
{
return QBrush( QColor( Qt::grey ) );
}
}
return QVariant();
}
这应该会有所帮助。