<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Attempt to create a circular mask over the image]]></title><description><![CDATA[<p dir="auto">I currently have an image and I wish to place a circular mask over it , so that anything anything outside the circular mask becomes transparent. This will give my image a circular effect. This is how I am attempting to do it. However This just draws a circle over the image</p>
<p dir="auto">@QPixmap Masking::GetNew(QImage&amp; img)<br />
{<br />
img.convertToFormat(QImage::Format_ARGB32);</p>
<p dir="auto">QPixmap source = QPixmap::fromImage(img);<br />
source = source.scaled(100,100,Qt::AspectRatioMode::IgnoreAspectRatio,Qt::TransformationMode::SmoothTransformation);</p>
<p dir="auto">QPainter painter(&amp;img);<br />
QBrush brsh;<br />
QColor colr;<br />
colr.setRgb(255,255,255,255); //white<br />
brsh.setColor(colr);</p>
<p dir="auto">painter.setCompositionMode(QPainter::CompositionMode_SourceOver);<br />
painter.setBrush(brsh);</p>
<p dir="auto">painter.drawEllipse(0,0,source.width()-5,source.width()-5);</p>
<p dir="auto">return QPixmap::fromImage(img); //Thisshouldhave the effect<br />
}<br />
@</p>
<p dir="auto">Any suggestion on what I might be doing wrong here. The above function is suppose to take in an image and apply a circular mask over it. and return the resulting image.</p>
]]></description><link>https://forum.qt.io/topic/38897/attempt-to-create-a-circular-mask-over-the-image</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 11:08:41 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/38897.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 12 Mar 2014 07:20:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Attempt to create a circular mask over the image on Wed, 12 Mar 2014 17:23:44 GMT]]></title><description><![CDATA[<p dir="auto">Yep that did the trick thanks</p>
]]></description><link>https://forum.qt.io/post/218282</link><guid isPermaLink="true">https://forum.qt.io/post/218282</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 12 Mar 2014 17:23:44 GMT</pubDate></item><item><title><![CDATA[Reply to Attempt to create a circular mask over the image on Wed, 12 Mar 2014 12:22:54 GMT]]></title><description><![CDATA[<p dir="auto">Take a look at this code and try it - is that what you want?<br />
@<br />
QPixmap GetNew(QImage&amp; img)<br />
{<br />
img.convertToFormat(QImage::Format_ARGB32);<br />
//blank copy image<br />
QImage imageOut(img.size(),QImage::Format_ARGB32);<br />
//painter on it<br />
QPainter painter(&amp;imageOut);<br />
//set opacity<br />
painter.setOpacity(0.5);<br />
painter.setBrush(Qt::white);<br />
painter.setPen(Qt::NoPen);<br />
//draw transparent image<br />
painter.drawImage(0,0,img);<br />
//set opacity<br />
painter.setOpacity(1);<br />
QPainterPath path(QPointF(100,100));<br />
//your mask - ellipse<br />
path.addEllipse(100,100,img.width()-200, img.height()-200);<br />
painter.setClipPath(path);<br />
//draw untransparent part of image<br />
painter.drawImage(0,0,img);<br />
return QPixmap::fromImage(imageOut);<br />
}<br />
@</p>
]]></description><link>https://forum.qt.io/post/218225</link><guid isPermaLink="true">https://forum.qt.io/post/218225</guid><dc:creator><![CDATA[MrMNight]]></dc:creator><pubDate>Wed, 12 Mar 2014 12:22:54 GMT</pubDate></item></channel></rss>