0

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 ?

Artyom
  • 11
  • 2

1 Answers1

0

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.

  • I use QItemDelegate and in there I implemented as you said in paint and it work's fine on WIndows. But after Qt release in linux stopped working. – Artyom Dec 16 '19 at 15:24
  • Well, probably some weird things being happen inside that linux distro. Maybe you need to recompile Qt binaries by yourself and see how it works. It is very simple, just use [qt online installer](https://www.qt.io/download-qt-installer?hsCtaTracking=99d9dd4f-5681-48d2-b096-470725510d34%7C074ddad0-fdef-4e53-8aa8-5e8a876d6ab4) and don't forget to tell your CMake/qmake where new binaries are. – Yevhenii Mamontov Dec 16 '19 at 15:28