<?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[[solved] How to work with masks in QPainter?]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I'm using Qt.5.3 and want to work with masks on a QImage to fill a region with a specific color.</p>
<p dir="auto">My mask is a 1Bit QImage (Mono).</p>
<p dir="auto">i thought, that i can handle this like:</p>
<p dir="auto">@<br />
QPainter overlayPainter(&amp;overlayClusters);<br />
QPixmap pixmap = QPixmap::fromImage(maskForegroundByUser);<br />
overlayPainter.setClipRegion(QRegion(pixmap));<br />
overlayPainter.fillRect(overlayClusters.rect(),brush);<br />
@</p>
<p dir="auto">but i can't create a QRegion from a QPixmap.</p>
<p dir="auto">Can someone help me?</p>
<p dir="auto"><em>//EDIT</em><br />
This solution works and has good performance:<br />
@<br />
QPainter overlayPainter(&amp;image);<br />
QBitmap bitmap = QBitmap::fromImage(mask); //mask is a QImage with the format Mono<br />
QRegion regionMask(bitmap);<br />
overlayPainter.setClipRegion(regionMask);<br />
overlayPainter.setCompositionMode(QPainter::CompositionMode_SourceOver);<br />
QBrush brush(Qt::blue,Qt::SolidPattern);<br />
overlayPainter.fillRect(image.rect(),brush);<br />
@<br />
Greetings</p>
]]></description><link>https://forum.qt.io/topic/46232/solved-how-to-work-with-masks-in-qpainter</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 22:55:37 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/46232.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 22 Sep 2014 18:18:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [solved] How to work with masks in QPainter? on Tue, 23 Sep 2014 07:12:45 GMT]]></title><description><![CDATA[<p dir="auto">Good !</p>
<p dir="auto">Since your mask is working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)</p>
]]></description><link>https://forum.qt.io/post/244933</link><guid isPermaLink="true">https://forum.qt.io/post/244933</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 23 Sep 2014 07:12:45 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] How to work with masks in QPainter? on Mon, 22 Sep 2014 21:56:14 GMT]]></title><description><![CDATA[<p dir="auto">Thanks,<br />
I thought about it, too. Now I see, that the QBitmap have a finction called "fromImage()".</p>
<p dir="auto">That works!</p>
]]></description><link>https://forum.qt.io/post/244904</link><guid isPermaLink="true">https://forum.qt.io/post/244904</guid><dc:creator><![CDATA[sheepy]]></dc:creator><pubDate>Mon, 22 Sep 2014 21:56:14 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] How to work with masks in QPainter? on Mon, 22 Sep 2014 20:53:51 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I haven't played with mask yet, but from the doc you can make a QBitmap from your maskForegroundByUser to use with setClipRegion</p>
<p dir="auto">Hope it helps</p>
]]></description><link>https://forum.qt.io/post/244895</link><guid isPermaLink="true">https://forum.qt.io/post/244895</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 22 Sep 2014 20:53:51 GMT</pubDate></item></channel></rss>