<?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[Issue with QLabel alignment properties]]></title><description><![CDATA[<p dir="auto">Hi everyone,</p>
<p dir="auto">I have a stupid issue, but cannot find any solutions for this. I think I may missing some understanding :</p>
<p dir="auto">I want to display an image in a Scroll Area, and I want it at the center. I made the following code:</p>
<pre><code>void MainWindow::setImage(const QImage &amp;newImage)
{
    scrollArea = new QScrollArea;
    imageLabel = new QLabel;

    scrollArea-&gt;setWidget(imageLabel);
    scrollArea-&gt;setFrameShape(QFrame::NoFrame);
    scrollArea-&gt;setStyleSheet("QScrollBar:vertical{width: 50px;}");

    ui-&gt;horizontalLayout-&gt;addWidget(scrollArea);

    image = newImage;
    if (image.colorSpace().isValid())
        image.convertToColorSpace(QColorSpace::SRgb);
    imageLabel-&gt;setPixmap(QPixmap::fromImage(image));

    imageLabel-&gt;adjustSize();
    imageLabel-&gt;setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
}
</code></pre>
<p dir="auto">It works, but the problem is that the image contained in the label remain aligned to the left, regardless of the  setAlignment(Qt::AlignHCenter | Qt::AlignVCenter) instruction.</p>
<p dir="auto">Any ideas why ?</p>
<p dir="auto">PS: I can't use QtCreator to change it.</p>
]]></description><link>https://forum.qt.io/topic/128944/issue-with-qlabel-alignment-properties</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 11:59:16 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/128944.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 29 Jul 2021 10:04:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Issue with QLabel alignment properties on Thu, 29 Jul 2021 10:19:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/clbsii">@<bdi>CLBSII</bdi></a> said in <a href="/post/673274">Issue with QLabel alignment properties</a>:</p>
<blockquote>
<p dir="auto">imageLabel-&gt;setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);</p>
</blockquote>
<p dir="auto">You've set the alignment to your label, not to your <code>QScrollArea</code></p>
<ul>
<li><a href="https://doc.qt.io/qt-5/qscrollarea.html#alignment-prop" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qscrollarea.html#alignment-prop</a></li>
</ul>
]]></description><link>https://forum.qt.io/post/673278</link><guid isPermaLink="true">https://forum.qt.io/post/673278</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Thu, 29 Jul 2021 10:19:36 GMT</pubDate></item><item><title><![CDATA[Reply to Issue with QLabel alignment properties on Thu, 29 Jul 2021 10:37:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/clbsii">@<bdi>CLBSII</bdi></a></p>
<p dir="auto">You're welcome. What you did is, you centered the pixmap on your <code>QLabel</code>, but the label itself still had the <code>QScrollArea</code>- widget default alignment, which is topLeft :)</p>
]]></description><link>https://forum.qt.io/post/673282</link><guid isPermaLink="true">https://forum.qt.io/post/673282</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Thu, 29 Jul 2021 10:37:40 GMT</pubDate></item><item><title><![CDATA[Reply to Issue with QLabel alignment properties on Thu, 29 Jul 2021 10:30:37 GMT]]></title><description><![CDATA[<p dir="auto">Thank you very much, it works.</p>
]]></description><link>https://forum.qt.io/post/673279</link><guid isPermaLink="true">https://forum.qt.io/post/673279</guid><dc:creator><![CDATA[CLBSII]]></dc:creator><pubDate>Thu, 29 Jul 2021 10:30:37 GMT</pubDate></item><item><title><![CDATA[Reply to Issue with QLabel alignment properties on Thu, 29 Jul 2021 10:19:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/clbsii">@<bdi>CLBSII</bdi></a> said in <a href="/post/673274">Issue with QLabel alignment properties</a>:</p>
<blockquote>
<p dir="auto">imageLabel-&gt;setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);</p>
</blockquote>
<p dir="auto">You've set the alignment to your label, not to your <code>QScrollArea</code></p>
<ul>
<li><a href="https://doc.qt.io/qt-5/qscrollarea.html#alignment-prop" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qscrollarea.html#alignment-prop</a></li>
</ul>
]]></description><link>https://forum.qt.io/post/673278</link><guid isPermaLink="true">https://forum.qt.io/post/673278</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Thu, 29 Jul 2021 10:19:36 GMT</pubDate></item></channel></rss>