After qt 5.11 release QHeaderView section colors stopped showing in linux. In windows works correctly. Has anyone encountered this problem?
I use QTableView with QHeaderView. Can I override paintSection function and do something to fix this issue ?
If you're using QAbstractTableModel
for your QTableView
- try to override
QVariant headerData(
int _section
, Qt::Orientation _orientation
, int _role /*= Qt::DisplayRole */
) const override;
If you do so, you will be able to write into the method body a mechanism of painting background in color you want. Something like this:
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();
}
This should help.