// Build the circle.
CircleImage.fill( Qt::transparent );
CirclePainter.
setRenderHint( QPainter::Antialiasing,
true );
CirclePainter.
setBrush( QBrush( ConicalGradient
) );
CirclePainter.setPen( Qt::black );
CirclePainter.drawEllipse( rect().adjusted( 1, 1, -1, -1 ) );
// Build the alpha channel.
AlphaChannelImage.fill( Qt::transparent );
QPainter AlphaChannelPainter
( &AlphaChannelImage
);
AlphaChannelPainter.
setRenderHint( QPainter::Antialiasing,
true );
AlphaChannelPainter.
setBrush( QBrush( AlphaGradient
) );
AlphaChannelPainter.setPen( Qt::white );
AlphaChannelPainter.drawEllipse( rect().adjusted( 1, 1, -1, -1 ) );
// Draw the circle.
for( int x = 0; x < CircleImage.width(); ++x )
{
for( int y = 0; y < CircleImage.height(); ++y )
{
const QColor Color
= CircleImage.
pixel( x, y
);
const QColor Alpha
= AlphaChannelImage.
pixel( x, y
);
p.
setPen( QColor( Color.
red(), Color.
green(), Color.
blue(), Alpha.
red() ) );
p.drawPoint( x, y );
}
}
// Build the circle.
QImage CircleImage( size(), QImage::Format_ARGB32 );
CircleImage.fill( Qt::transparent );
QPainter CirclePainter( &CircleImage );
CirclePainter.setRenderHint( QPainter::Antialiasing, true );
CirclePainter.setBrush( QBrush( ConicalGradient ) );
CirclePainter.setPen( Qt::black );
CirclePainter.drawEllipse( rect().adjusted( 1, 1, -1, -1 ) );
// Build the alpha channel.
QImage AlphaChannelImage( size(), QImage::Format_RGB32 );
AlphaChannelImage.fill( Qt::transparent );
QPainter AlphaChannelPainter( &AlphaChannelImage );
AlphaChannelPainter.setRenderHint( QPainter::Antialiasing, true );
AlphaChannelPainter.setBrush( QBrush( AlphaGradient ) );
AlphaChannelPainter.setPen( Qt::white );
AlphaChannelPainter.drawEllipse( rect().adjusted( 1, 1, -1, -1 ) );
// Draw the circle.
for( int x = 0; x < CircleImage.width(); ++x )
{
for( int y = 0; y < CircleImage.height(); ++y )
{
const QColor Color = CircleImage.pixel( x, y );
const QColor Alpha = AlphaChannelImage.pixel( x, y );
p.setPen( QColor( Color.red(), Color.green(), Color.blue(), Alpha.red() ) );
p.drawPoint( x, y );
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks