<?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[QGraphicsView has ~1 pixel margin for QPixmap]]></title><description><![CDATA[<p dir="auto">I've created a QMainWindow, which sets it's center widget to a QGraphicsView.<br />
The QGraphicsView displays a QGraphicsScene with a single QPixmap inside it.</p>
<p dir="auto">The whole thing spans across all Screens and just displays a screenshot of all screens in the QPixmap.</p>
<p dir="auto">This is my constructor:</p>
<pre><code>// These are in the initializer list
auto scene = new QGraphicsScene;
auto view = new QGraphicsView(scene, this);

// Gets a Screenshot of all screens
scene-&gt;addPixmap(Screenshot::getScreenshotFull());

view-&gt;setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view-&gt;setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view-&gt;show();

setCentralWidget(view);
</code></pre>
<p dir="auto">Now once this window gets displayed, the Screenshot is moved to the right and down by about one pixel. (Which means there is a white border at the left and top screen)</p>
<p dir="auto">How it should be:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/3ec04897-f20e-4a17-ba31-29a2b4a9a641.PNG" alt="0_1518270814992_without.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto">How it actually is (I've made the top border red, left border white):<br />
<img src="https://ddgobkiprc33d.cloudfront.net/7e4d04d4-9ab1-4296-85ca-6a0ff485d6db.PNG" alt="0_1518270850998_with.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto">It seems like the QGraphicsScene indents all contents by one pixel so it is "visually inside" the outer widget/container (QGraphicsView)</p>
<p dir="auto">Is there any way to get around this and remove that border?</p>
<p dir="auto">When I used a QLabel and set the Pixmap via that, there was no border. I moved to the QGraphicsView because apparently that one is better if I want to draw plenty of rectangles onto it later on.. is that correct?</p>
<p dir="auto">This whole thing is a Screenshot tool, so only an overlay where the user can crop out a rectangle (and also I can highlight windows with rectangles), is it a good idea for that to use a QMainWindow and by code only or should I use .ui files? Also is QGraphicsView the right option here? I want to draw a rectangle whenever the user hovers over certain areas.</p>
<p dir="auto">Thanks.</p>
]]></description><link>https://forum.qt.io/topic/87669/qgraphicsview-has-1-pixel-margin-for-qpixmap</link><generator>RSS for Node</generator><lastBuildDate>Fri, 15 May 2026 22:46:58 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/87669.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 10 Feb 2018 13:53:32 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QGraphicsView has ~1 pixel margin for QPixmap on Sat, 10 Feb 2018 17:07:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrousavy">@<bdi>mrousavy</bdi></a> The solution is to set no frame style.</p>
<pre><code>view-&gt;setFrameStyle(QFrame::NoFrame);
</code></pre>
]]></description><link>https://forum.qt.io/post/441605</link><guid isPermaLink="true">https://forum.qt.io/post/441605</guid><dc:creator><![CDATA[mrousavy]]></dc:creator><pubDate>Sat, 10 Feb 2018 17:07:17 GMT</pubDate></item></channel></rss>