<?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[[help!] QGraphicsScene background image manipulation - adding the margin next to the background image]]></title><description><![CDATA[<p dir="auto">Hello Qt deveopers :).</p>
<p dir="auto">I have some problems regarding the QGraphicsScene image manipulation.</p>
<p dir="auto">However, before describing my main problem I would like to ask You about different issue: some time ago I had registered here and today I wanted to log-in with that old account. I forgot my password so I followed the "password reseting" procedure, but it failed. I received an email with a new temporary pass but after typing it Qt-project web shown the login error... I reseted the password for 4 times but unsuccessfully... Do You know how to fix this?</p>
<p dir="auto">Regarding my problem with the image: I have created the scene, view and some items placed on the scene. I set the background image with following way:</p>
<p dir="auto">@<br />
QString m_strBackgroundPath("/home/pic.jpg");<br />
QImage oImage( m_strBackgroundPath );<br />
m_pScene-&gt;setSceneRect( oImage.rect() );<br />
m_pScene-&gt;setBackgroundBrush( oImage );<br />
@</p>
<p dir="auto">So far everything is fine: the picture is painted in the background, the items are painted/shown "on" this picture and everything is presented in the view.</p>
<p dir="auto">But, sometimes, for certain items I would like to show a little information in the right side of the view. The information is shown in some-kind of information widget. The problem is that this information widget may overlap the item. In such case I would like to move the whole scene with all items to the left, so the focused item would be still visible.  I figured out that in the right side of the scene I can add some margin and then "move" the view. I tried to extend the scene rectangle to the right with the following code:</p>
<p dir="auto">@<br />
QRectF myGraphicsScene::sceneRect() const<br />
{<br />
const QRectF oSceneRect = QGraphicsScene::sceneRect();<br />
QRectF oAdjRect(oSceneRect);<br />
oAdjRect.adjust(0,0,150,0);<br />
qDebug() &lt;&lt; "CPTGraphicsScene::sceneRect()" &lt;&lt; oSceneRect &lt;&lt; oAdjRect;<br />
return oAdjRect;<br />
}<br />
@</p>
<p dir="auto">and draw the margin this way:<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> myGraphicsScene::drawBackground(QPainter* pPainter, const QRectF&amp; rRect)<br />
{<br />
QBrush oBrush = backgroundBrush();</p>
<p dir="auto">QRectF oRect( rRect.x()-rRect.width(), rRect.y()<br />
, 150, rRect.height() );<br />
qDebug() &lt;&lt; "CPTGraphicsScene::drawBackground!" &lt;&lt; rRect &lt;&lt; sceneRect() &lt;&lt; oRect;</p>
<p dir="auto">if ( oBrush.style() != Qt::NoBrush )<br />
{<br />
pPainter-&gt;save();<br />
pPainter-&gt;setBrushOrigin(0, 0);<br />
pPainter-&gt;fillRect(rRect, oBrush);<br />
pPainter-&gt;fillRect( oRect, Qt::red );<br />
pPainter-&gt;restore();<br />
}<br />
}//END drawBackground()@</p>
<p dir="auto">Value "150" is just for tests here ;). Unfortunately this doesn't work... :(</p>
<p dir="auto">Do You have any idea what I'm doing wrong...</p>
<p dir="auto">I would be grateful for any hind and advice.</p>
<p dir="auto">Robert :)</p>
]]></description><link>https://forum.qt.io/topic/33921/help-qgraphicsscene-background-image-manipulation-adding-the-margin-next-to-the-background-image</link><generator>RSS for Node</generator><lastBuildDate>Sun, 07 Jun 2026 22:26:32 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/33921.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 Nov 2013 12:49:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [help!] QGraphicsScene background image manipulation - adding the margin next to the background image on Tue, 19 Nov 2013 07:55:47 GMT]]></title><description><![CDATA[<p dir="auto">the rRect parameter is the exposed rectangle in the scene. I believe you want the background image as the scene background, meaning it should scroll with the items?</p>
<p dir="auto">try this:<br />
@<br />
void myGraphicsScene::drawBackground(QPainter* pPainter, const QRectF&amp; rRect)<br />
{<br />
QBrush oBrush = backgroundBrush();<br />
QRectF sceneRect = this-&gt;sceneRect();</p>
<pre><code> pPainter-&gt;save();
     pPainter-&gt;setClipRegion( QRegion( rRect.toRect() ) );   //just some optimization
     pPainter-&gt;fillRect( sceneRect, Qt::red );  //you may optimize this line
     pPainter-&gt;fillRect( sceneRect.translated(-150,0), oBrush );
 pPainter-&gt;restore(); 
</code></pre>
<p dir="auto">}<br />
@</p>
]]></description><link>https://forum.qt.io/post/204524</link><guid isPermaLink="true">https://forum.qt.io/post/204524</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 19 Nov 2013 07:55:47 GMT</pubDate></item><item><title><![CDATA[Reply to [help!] QGraphicsScene background image manipulation - adding the margin next to the background image on Tue, 19 Nov 2013 07:41:08 GMT]]></title><description><![CDATA[<p dir="auto">Any idea? Anybody?</p>
]]></description><link>https://forum.qt.io/post/204521</link><guid isPermaLink="true">https://forum.qt.io/post/204521</guid><dc:creator><![CDATA[poorBob]]></dc:creator><pubDate>Tue, 19 Nov 2013 07:41:08 GMT</pubDate></item><item><title><![CDATA[Reply to [help!] QGraphicsScene background image manipulation - adding the margin next to the background image on Sun, 10 Nov 2013 17:32:23 GMT]]></title><description><![CDATA[<p dir="auto">Bump, bump :(</p>
]]></description><link>https://forum.qt.io/post/203505</link><guid isPermaLink="true">https://forum.qt.io/post/203505</guid><dc:creator><![CDATA[poorBob]]></dc:creator><pubDate>Sun, 10 Nov 2013 17:32:23 GMT</pubDate></item><item><title><![CDATA[Reply to [help!] QGraphicsScene background image manipulation - adding the margin next to the background image on Wed, 06 Nov 2013 13:26:51 GMT]]></title><description><![CDATA[<p dir="auto">Hello, hello again :). Do You have any idea?</p>
]]></description><link>https://forum.qt.io/post/203028</link><guid isPermaLink="true">https://forum.qt.io/post/203028</guid><dc:creator><![CDATA[poorBob]]></dc:creator><pubDate>Wed, 06 Nov 2013 13:26:51 GMT</pubDate></item></channel></rss>