【发布时间】:2019-12-16 14:17:28
【问题描述】:
在 qt 5.11 发布后 QHeaderView 部分颜色停止在 linux 中显示。 在 Windows 中正常工作。 有人遇到过这个问题吗?
我将 QTableView 与 QHeaderView 一起使用。我可以重写paintSection 函数并做一些事情来解决这个问题吗?
【问题讨论】:
在 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();
}
这应该会有所帮助。
【讨论】: