Skip to content
Permalink
Browse files

Use rounded rectangles for preview icons in QgsColorButtonV2

  • Loading branch information
nyalldawson committed Aug 11, 2014
1 parent a30ddaa commit dd1fe45193d4868bdef852a2939eda86eb1aaac5
Showing with 13 additions and 17 deletions.
  1. +13 −17 src/gui/qgscolorbuttonv2.cpp
@@ -528,30 +528,26 @@ void QgsColorButtonV2::setButtonBackground( const QColor color )
}
//create an icon pixmap
QPixmap pixmap( mIconSize );
pixmap.fill( Qt::transparent );

QRect rect( 0, 0, mIconSize.width(), mIconSize.height() );
QPainter p;
p.begin( &pixmap );
p.setRenderHint( QPainter::Antialiasing );
p.setPen( Qt::NoPen );
if ( useAlpha && backgroundColor.alpha() < 255 )
{
QRect rect( 0, 0, mIconSize.width(), mIconSize.height() );
QPainter p;
p.begin( &pixmap );

//start with checkboard pattern
QBrush checkBrush = QBrush( transparentBackground() );
p.setPen( Qt::NoPen );
p.setBrush( checkBrush );
p.drawRect( rect );

//draw semi-transparent color on top
p.setRenderHint( QPainter::Antialiasing );
p.setBrush( backgroundColor );
p.drawRect( rect );
p.end();
}
else
{
//no transparency, nice and easy
pixmap.fill( backgroundColor );
p.drawRoundedRect( rect, 3, 3 );
}

//draw semi-transparent color on top
p.setBrush( backgroundColor );
p.drawRoundedRect( rect, 3, 3 );
p.end();

setIconSize( mIconSize );
setIcon( pixmap );
}

0 comments on commit dd1fe45

Please sign in to comment.
You can’t perform that action at this time.