サブクラス化QStyledItemDelegate
(ペイント関数のみ) を行い、データのカスタム モデルQTableview
と共に適用しました。QAbstractTableModel
テーブルのセルは正しく描画され、選択されたときも正しく描画されますが、マウスオーバーの色はそうではありません。何が恋しいですか?ペイント機能は次のとおりです。セルはすべて黒で、選択したセルは緑色になりますが、マウスがセルの上にあると赤色になりません。
void Mydelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
if (option.state & QStyle::State_MouseOver) {
painter->fillRect(option.rect, QColor(Qt::red));
} else if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, QColor(Qt::green));
} else painter->fillRect(option.rect, QColor(Qt::black));
painter->restore();
}