QTableviewとQAbstractTableModelを使用して1つのテーブルを作成しました。QHeaderViewを使用して垂直ヘッダーを追加しました。ヘッダーセルの1つで、デリゲートを使用します。
デリゲートを使用していますが、影響はありません。
私が間違っているところはどこですか?
この問題は自分で持っていました。Qtのドキュメントからの答えは単純で面倒です。
注:各ヘッダーは、各セクション自体のデータをレンダリングし、デリゲートに依存しません。その結果、ヘッダーのsetItemDelegate()関数を呼び出しても効果はありません。
つまり、QHeaderViewでデリゲートを使用することはできません。
記録のために、QHeaderViewセクションのスタイルを設定する場合は、ヘッダーデータモデル(Qt :: FontRoleの変更など)を介してスタイルを設定するか、独自のQHeaderViewを派生させる(忘れずにに渡す必要があります)。テーブルに「setVerticalHeader()」)を追加し、そのpaintSection()関数を上書きします。すなわち:
void YourCustomHeaderView::paintSection(QPainter* in_p_painter, const QRect& in_rect, int in_section) const
{
if (nullptr == in_p_painter)
return;
// Paint default sections
in_p_painter->save();
QHeaderView::paintSection(in_p_painter, in_rect, in_section);
in_p_painter->restore();
// Paint your custom section content OVER a specific, finished
// default section (identified by index in this case)
if (m_your_custom_section_index == in_section)
{
QPen pen = in_p_painter->pen();
pen.setWidthF(5.5);
pen.setColor(QColor(m_separator_color));
in_p_painter->setPen(pen);
in_p_painter->drawLine(in_rect.right(), in_rect.top(), in_rect.right(), in_rect.bottom());
}
}
もちろん、この単純化された例は、代わりにスタイルシートを介して簡単に実行できますが、理論的には、この方法を使用して好きなものを描くことができます。