【问题标题】:Issue in QHeaderView section colors after qt release (5.11) in linux在 linux 中 qt 发布 (5.11) 后 QHeaderView 部分颜色出现问题
【发布时间】:2019-12-16 14:17:28
【问题描述】:

在 qt 5.11 发布后 QHeaderView 部分颜色停止在 linux 中显示。 在 Windows 中正常工作。 有人遇到过这个问题吗?

我将 QTableView 与 QHeaderView 一起使用。我可以重写paintSection 函数并做一些事情来解决这个问题吗?

【问题讨论】:

    标签: c++ qt qt5.11


    【解决方案1】:

    如果您使用 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();
    }
    

    这应该会有所帮助。

    【讨论】:

    • 我使用 QItemDelegate 并在其中按照您在绘画中所说的那样实现,它在 WINdows 上运行良好。但是在 linux 中的 Qt 版本停止工作之后。
    • 好吧,Linux 发行版中可能正在发生一些奇怪的事情。也许您需要自己重新编译 Qt 二进制文件,看看它是如何工作的。这很简单,只需使用qt online installer,别忘了告诉你的 CMake/qmake 新的二进制文件在哪里。
    猜你喜欢
    • 2013-01-16
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 2020-07-21
    • 1970-01-01
    相关资源
    最近更新 更多