From cc049ea0d7b24a274c774b5c3fc08f4d5e2639d8 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Fri, 29 Nov 2024 08:14:56 +0700 Subject: [PATCH] [ui] Apply same semi-opaque color rendering to various color lists (raster renderers, color scheme lists, etc) --- src/gui/qgscolorschemelist.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/gui/qgscolorschemelist.cpp b/src/gui/qgscolorschemelist.cpp index 654ab06b8a3e..a50b1252d0aa 100644 --- a/src/gui/qgscolorschemelist.cpp +++ b/src/gui/qgscolorschemelist.cpp @@ -704,7 +704,7 @@ void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewIte painter->drawRect( option.rect ); } - const QColor color = index.model()->data( index, Qt::DisplayRole ).value(); + QColor color = index.model()->data( index, Qt::DisplayRole ).value(); if ( !color.isValid() ) { return; @@ -729,11 +729,23 @@ void QgsColorSwatchDelegate::paint( QPainter *painter, const QStyleOptionViewIte const QBrush checkBrush = QBrush( transparentBackground() ); painter->setBrush( checkBrush ); painter->drawRoundedRect( rect, cornerSize, cornerSize ); + //draw semi-transparent color on top + painter->setBrush( color ); + painter->drawRoundedRect( rect, cornerSize, cornerSize ); + //draw fully opaque color on the left side + const QRectF clipRect( rect.left(), rect.top(), + static_cast( rect.width() ) / 2.0, + rect.height() ); + painter->setClipRect( clipRect ); + color.setAlpha( 255 ); + painter->setBrush( color ); + painter->drawRoundedRect( rect, cornerSize, cornerSize ); + } + else + { + painter->setBrush( color ); + painter->drawRoundedRect( rect, cornerSize, cornerSize ); } - - //draw semi-transparent color on top - painter->setBrush( color ); - painter->drawRoundedRect( rect, cornerSize, cornerSize ); } QPixmap QgsColorSwatchDelegate::transparentBackground() const