この質問は、この投稿をさらに発展させたものであり、これと似ているように見えるかもしれませんが、異なります。
QHeaderView::paintSection
モデルから返された背景が尊重されるように、を再実装しようとしています。私はこれをやろうとしました
void Header::paintSection(QPainter * painter, const QRect & rect, int logicalIndex) const
{
QVariant bg = model()->headerData(logicalIndex, Qt::Horizontal, Qt::BackgroundRole);
// try before
if(bg.isValid()) // workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-46216
painter->fillRect(rect, bg.value<QBrush>());
QHeaderView::paintSection(painter, rect, logicalIndex);
// try after
if(bg.isValid()) // workaround for Qt bug https://bugreports.qt.io/browse/QTBUG-46216
painter->fillRect(rect, bg.value<QBrush>());
}
しかし、それはうまくいきませんでした-私がQHeaderView::paintSection
電話をかけた場合、ペインターで描いたものは何も見えません(対角線も描いてみました)。通話を削除するQHeaderView::paintSection
と、線と背景が表示されます。の前と後にfillRect
呼び出しQHeaderView::paintSection
を行っても、違いはありません。
QHeaderView::paintSection
その上に何かを描くことができないのは何なのだろうか。そして、すべてを再実装せずにそれを克服する方法QHeaderView::paintSection
はありますか?
私がする必要があるのは、特定のセルに特定の色合いを追加することだけです-セル内のすべて(テキスト、アイコン、グラデーションの背景など)をそのままペイントしたいのですが...