Playing with colors.
This commit is contained in:
@@ -141,7 +141,7 @@ QSize BCItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelI
|
||||
}
|
||||
|
||||
|
||||
void BCItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
void BCItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
/*
|
||||
// 1. Standard-Zeichnen (Text, Hintergrund, Selection) durchführen
|
||||
@@ -193,17 +193,57 @@ void BCItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option
|
||||
|
||||
if (m_rowOpacities.contains(row))
|
||||
{
|
||||
/*
|
||||
qreal opacity = m_rowOpacities.value(row);
|
||||
if (opacity > 0.01) {
|
||||
if (opacity > 0.01)
|
||||
{
|
||||
painter->save();
|
||||
painter->setOpacity(opacity);
|
||||
painter->fillRect(option.rect, QColor(255, 140, 0, 120));
|
||||
painter->restore();
|
||||
}
|
||||
*/
|
||||
paintHighlightRow(painter,option,index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BCItemDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
int row = index.row();
|
||||
qreal opacity = m_rowOpacities.value(row);
|
||||
painter->setOpacity(opacity);
|
||||
// Margin von 4px
|
||||
QRect itemRect = option.rect.adjusted(4, 4, -4, -4);
|
||||
|
||||
// Border von 2px berücksichtigen (nach innen)
|
||||
QRect contentRect = itemRect.adjusted(2, 2, -2, -2);
|
||||
|
||||
// Hintergrund (weiß)
|
||||
painter->setBrush(Qt::white);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->drawRoundedRect(itemRect, 8, 8);
|
||||
|
||||
// Border (2px solid #2196F3)
|
||||
QPen borderPen( Qt::red, 2);
|
||||
painter->setPen(borderPen);
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawRoundedRect(itemRect, 8, 8);
|
||||
|
||||
// Padding von 8px für den Content
|
||||
QRect textRect = contentRect.adjusted(8, 8, -8, -8);
|
||||
|
||||
// Text zeichnen
|
||||
painter->setPen(Qt::black); // oder option.palette.color(QPalette::Text)
|
||||
QString text = index.data(Qt::DisplayRole).toString();
|
||||
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
void BCItemDelegate::onHighlightRow(int row)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user