<?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[Problem aligning widgets in QVBoxLayout]]></title><description><![CDATA[<p dir="auto">I have a MainWindow with a centralWidget that contains a main QHBoxLayout. This main layout in turn contains a QHBoxLayout and, to the right of this, a QVBoxLayout. The QVBoxLayout contains three QLabel widgets that I have added using vboxlayout-&gt;addWidget(aWidget, 0, Qt::AlignHCenter). Problem is that no matter what alignment flags I pass to addWidget my labels always end up aligned to the left of the layout.</p>
<p dir="auto">Abridged code:</p>
<p dir="auto">@<br />
MainWindow::MainWindow(QWidget *parent)<br />
: QMainWindow(parent)<br />
{<br />
QWidget centralWidget = new QWidget;</p>
<pre><code>centralLayout = new QHBoxLayout;

aclockLayout = new QHBoxLayout;
aclockLayout-&gt;addWidget(aclock, 0, Qt::AlignCenter);

counterLayout = new QVBoxLayout;
counterlayout-&gt;addWidget(vbclock, 0, Qt::AlignHCenter);
counterlayout-&gt;addWidget(dtdisplay, 0 Qt::AlignHCenter);
counterLayout-&gt;addWidget(tzdisplay, 0, Qt::AlignHCenter);

centralLayout-&gt;addLayout(aclockLayout);
centralLayout-&gt;addLayout(counterLayout);
centralWidget-&gt;setLayout(centralLayout);
setCentralWidget(centralWidget);
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">All I want is for my three widgets to be aligned on the vertical center line of the QVBoxLayout. What am I missing here?</p>
]]></description><link>https://forum.qt.io/topic/24277/problem-aligning-widgets-in-qvboxlayout</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 05:27:25 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/24277.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 Feb 2013 23:38:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem aligning widgets in QVBoxLayout on Fri, 15 Feb 2013 00:05:44 GMT]]></title><description><![CDATA[<p dir="auto">QLabel is by default left-aligned and takes up all available space to the right. Try setting the text alignment of the labels.<br />
<a href="http://doc.qt.digia.com/stable/qlabel.html#alignment-prop" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.digia.com/stable/qlabel.html#alignment-prop</a></p>
]]></description><link>https://forum.qt.io/post/167279</link><guid isPermaLink="true">https://forum.qt.io/post/167279</guid><dc:creator><![CDATA[frederik]]></dc:creator><pubDate>Fri, 15 Feb 2013 00:05:44 GMT</pubDate></item></channel></rss>