<?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[different size buttons on qlayout]]></title><description><![CDATA[<p dir="auto">i created two buttons and a vertical layout and i want both buttons to be positioned in the center of their row. but their widths are different and that makes my work seem hard, and only the second (bottom-most) button is in the center. what's the problem with the first one?</p>
<p dir="auto">and by the way, why don't the commented lines make a difference in the code?</p>
<pre><code>#include &lt;qapplication.h&gt;
#include &lt;qpushbutton.h&gt;
#include &lt;qlayout.h&gt;

int main(int argc, char **argv) {

    QApplication app(argc, argv);

    QWidget window;
    window.setFixedSize(200, 100);

    QPushButton *buttonInfo = new QPushButton("Info", &amp;window);
    //buttonInfo-&gt;setGeometry(10, 10, 80, 30);
    buttonInfo-&gt;setMaximumWidth(80);

    QPushButton *buttonQuit = new QPushButton("Quit", &amp;window);
    //buttonQuit-&gt;setGeometry(10, 10, 110, 30);
    buttonQuit-&gt;setMinimumWidth(110);

    QObject::connect(buttonInfo, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
    QObject::connect(buttonQuit, SIGNAL(clicked()), qApp, SLOT(quit()));

    QVBoxLayout *layout = new QVBoxLayout;
    layout-&gt;addWidget(buttonInfo);
    layout-&gt;addWidget(buttonQuit);
    layout-&gt;setAlignment(Qt::AlignCenter);

    window.setLayout(layout);
    window.show();

    return app.exec();
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/82334/different-size-buttons-on-qlayout</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 00:35:08 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/82334.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 12 Aug 2017 18:50:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to different size buttons on qlayout on Sat, 12 Aug 2017 19:55:09 GMT]]></title><description><![CDATA[<p dir="auto">First you've should created a horizontal layout and added the buttonInfo widget with Qt::AlignHCenter argument, then created a vertical layout and added the horizontal layout to it and the quitButton widget. Check this code, worked as you wanted to:</p>
<pre><code>#include &lt;qapplication.h&gt;
#include &lt;qpushbutton.h&gt;
#include &lt;qlayout.h&gt;

int main(int argc, char **argv) {

    QApplication app(argc, argv);

    QWidget window;
    window.setFixedSize(200, 100);

    QPushButton *buttonInfo = new QPushButton("Info", &amp;window);
    //buttonInfo-&gt;setGeometry(10, 10, 80, 30);
    buttonInfo-&gt;setMaximumWidth(80);

    QPushButton *buttonQuit = new QPushButton("Quit", &amp;window);
    //buttonQuit-&gt;setGeometry(10, 10, 110, 30);
    buttonQuit-&gt;setMinimumWidth(110);

    QObject::connect(buttonInfo, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
    QObject::connect(buttonQuit, SIGNAL(clicked()), qApp, SLOT(quit()));

    QHBoxLayout *hlayout = new QHBoxLayout;
    QVBoxLayout *vlayout = new QVBoxLayout;

    hlayout-&gt;addWidget(buttonInfo, 0, Qt::AlignHCenter);

    vlayout-&gt;addLayout(hlayout);
    vlayout-&gt;addWidget(buttonQuit);
    vlayout-&gt;setAlignment(Qt::AlignCenter);

    window.setLayout(vlayout);
    window.show();

    return app.exec();
}
</code></pre>
<p dir="auto">The commented lines doesn't work because you assigned those widgets to a layout, then the layout customizes their size for its needs.</p>
]]></description><link>https://forum.qt.io/post/410056</link><guid isPermaLink="true">https://forum.qt.io/post/410056</guid><dc:creator><![CDATA[denko]]></dc:creator><pubDate>Sat, 12 Aug 2017 19:55:09 GMT</pubDate></item></channel></rss>