<?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[[Solved] Dynamic Layout should be better then that what I&#x27;ve done]]></title><description><![CDATA[<p dir="auto">Hi there,</p>
<p dir="auto">I'm very new to QT (using 5.4). First, I get trough the zetcode Tutorial (for QT 4) and now I try to develop my very first own Application with QT.</p>
<p dir="auto">My problem: to get the UI Dynamic Layout in a nice behaviour (I mean a behaviour where it looks good when its small and when its big), I think I've used more lines then necessary.</p>
<p dir="auto">My Code:<br />
<em>mainwindow.cpp</em><br />
@#include "mainwindow.h"</p>
<p dir="auto">MainWindow::MainWindow(QWidget *parent) : QWidget(parent)<br />
{<br />
/<em>VBox deklarieren - nur einmal QLayout definieren</em>/<br />
QVBoxLayout *vbox = new QVBoxLayout(this);<br />
vbox-&gt;setMargin(20);<br />
/<em>HBoxes deklarieren</em>/<br />
QHBoxLayout *hbox_1 = new QHBoxLayout();<br />
QHBoxLayout *hbox_2 = new QHBoxLayout();<br />
QHBoxLayout *hbox_3 = new QHBoxLayout();</p>
<pre><code>/*Strings definieren*/
QLabel *l_title    = new QLabel("Titel", this);
QLabel *l_subtitle = new QLabel("Subtitel", this);

/*Strings formatieren*/
l_title-&gt;setAlignment(Qt::AlignCenter);
l_title-&gt;setFont(QFont("Calibri", 36, QFont::Bold));
l_title-&gt;setStyleSheet("QLabel {color: green}");

l_subtitle-&gt;setAlignment(Qt::AlignCenter);

/*Buttons definieren*/
QPushButton *b_1 = new QPushButton("Button 1 ", this);
    b_1-&gt;setMaximumWidth(200);
QPushButton *b_2 = new QPushButton("Button 2", this);
    b_2-&gt;setMaximumWidth(200);
QPushButton *b_3  = new QPushButton("Button 3", this);
    b_3 -&gt;setMaximumWidth(200);

/*Layout definieren*/
    /*HBox1*/
vbox-&gt;addStretch(1);
hbox_1-&gt;addWidget(b_1, 0, Qt::AlignVCenter);
vbox-&gt;addStretch(1);

    /*HBox2*/
vbox-&gt;addStretch(1);
hbox_2-&gt;addWidget(b_2, 0, Qt::AlignVCenter);
vbox-&gt;addStretch(1);

    /*HBox3*/
vbox-&gt;addStretch(1);
hbox_3-&gt;addWidget(b_3,  0, Qt::AlignVCenter);
vbox-&gt;addStretch(1);

    /*VBox*/
vbox-&gt;addStretch(1);
vbox-&gt;addWidget(l_title,    0, Qt::AlignHCenter);
vbox-&gt;addStretch(1);
vbox-&gt;addWidget(l_subtitle, 0, Qt::AlignHCenter);
vbox-&gt;addStretch(5);
vbox-&gt;addLayout(hbox_1);
vbox-&gt;addStretch(1);
vbox-&gt;addLayout(hbox_2);
vbox-&gt;addStretch(1);
vbox-&gt;addLayout(hbox_3);
vbox-&gt;addStretch(10);
vbox-&gt;addSpacing(50);

/*Layout setzen*/
setLayout(vbox);
</code></pre>
<p dir="auto">}@</p>
<p dir="auto">It would be nice If someone can give me some hints.<br />
greetings<br />
-casisto</p>
]]></description><link>https://forum.qt.io/topic/51316/solved-dynamic-layout-should-be-better-then-that-what-i-ve-done</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Nov 2026 04:57:38 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/51316.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 17 Feb 2015 17:17:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Solved] Dynamic Layout should be better then that what I&#x27;ve done on Thu, 19 Feb 2015 17:18:32 GMT]]></title><description><![CDATA[<p dir="auto">Ok,</p>
<p dir="auto">now I've get it.<br />
Funny thing, I had change the first line to this:<br />
@    QVBoxLayout *vbox = new QVBoxLayout;@</p>
<p dir="auto">Comment out the<br />
@setLayout(vbox);@</p>
<p dir="auto">has finished in an "unexpected close".</p>
<p dir="auto">Thanks, Samuel</p>
]]></description><link>https://forum.qt.io/post/262194</link><guid isPermaLink="true">https://forum.qt.io/post/262194</guid><dc:creator><![CDATA[casisto]]></dc:creator><pubDate>Thu, 19 Feb 2015 17:18:32 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Dynamic Layout should be better then that what I&#x27;ve done on Wed, 18 Feb 2015 21:42:50 GMT]]></title><description><![CDATA[<p dir="auto">I've missed that one so:</p>
<p dir="auto">@QVBoxLayout *vbox = new QVBoxLayout(this);@</p>
<p dir="auto">Here you already set vbox as layout of your widget so the call to</p>
<p dir="auto">@setLayout(vbox);@</p>
<p dir="auto">is causing the warning.</p>
]]></description><link>https://forum.qt.io/post/262073</link><guid isPermaLink="true">https://forum.qt.io/post/262073</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 18 Feb 2015 21:42:50 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Dynamic Layout should be better then that what I&#x27;ve done on Wed, 18 Feb 2015 17:42:18 GMT]]></title><description><![CDATA[<p dir="auto">Hi sGaist,</p>
<p dir="auto">thanks, and thanks for removing the Spam.</p>
<p dir="auto">I've now edited my Layout with a loop. But I get the error:<br />
"QLayout::addChildLayout: layout "" already has a parent"</p>
<p dir="auto">The arrays a declared in mainwindow.h and lang.h:<br />
QPushButton *btn[2];<br />
QHBoxLayout *hbox[2];<br />
QString str_btn[] = {"btn1", "btn2", "btn3"};</p>
<p dir="auto">@#include "mainwindow.h"<br />
#include "lang.h"</p>
<p dir="auto">MainWindow::MainWindow(QWidget *parent) : QWidget(parent)<br />
{<br />
/<em>VBox deklarieren - nur einmal QLayout definieren</em>/<br />
QVBoxLayout *vbox = new QVBoxLayout(this);<br />
vbox-&gt;setMargin(20);</p>
<pre><code>/*Strings definieren*/
QLabel *l_title    = new QLabel("Titel", this);
QLabel *l_subtitle = new QLabel("Subtitel", this);

/*Strings formatieren*/
l_title-&gt;setAlignment(Qt::AlignCenter);
l_title-&gt;setFont(QFont("Calibri", 36, QFont::Bold));
l_title-&gt;setStyleSheet("QLabel {color: green}");

l_subtitle-&gt;setAlignment(Qt::AlignCenter);

for(int i = 0; i &lt; 3; i++)
{
    /*Buttons definieren*/
    btn[i] = new QPushButton(str_btn[i], this);

    /*Hboxes definieren*/
    hbox[i] = new QHBoxLayout();

    /*HBoxLayout definieren*/
    hbox[i]-&gt;addStretch(1);
    hbox[i]-&gt;addWidget(btn[i], 0, Qt::AlignVCenter);
    hbox[i]-&gt;addStretch(1);
}

vbox-&gt;addStretch(1);
vbox-&gt;addWidget(l_title,    0, Qt::AlignHCenter);
vbox-&gt;addStretch(1);
vbox-&gt;addWidget(l_subtitle, 0, Qt::AlignHCenter);
vbox-&gt;addStretch(5);
vbox-&gt;addLayout(hbox[0]);
vbox-&gt;addStretch(1);
vbox-&gt;addLayout(hbox[1]);
vbox-&gt;addStretch(1);
vbox-&gt;addLayout(hbox[2]);
vbox-&gt;addStretch(1);

/*Layout setzen*/
setLayout(vbox);
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">It would be great if you could give me hint what throw the warning? (Also, I get the first button in the upper left corner, but I think the first error conditioned the second...)</p>
]]></description><link>https://forum.qt.io/post/262061</link><guid isPermaLink="true">https://forum.qt.io/post/262061</guid><dc:creator><![CDATA[casisto]]></dc:creator><pubDate>Wed, 18 Feb 2015 17:42:18 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Dynamic Layout should be better then that what I&#x27;ve done on Tue, 17 Feb 2015 22:05:38 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">Spam removed</p>
<p dir="auto">Your code doesn't look bad, you could use a loop to create and setup your three buttons since you do three times the exact the same thing</p>
]]></description><link>https://forum.qt.io/post/261937</link><guid isPermaLink="true">https://forum.qt.io/post/261937</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 17 Feb 2015 22:05:38 GMT</pubDate></item><item><title><![CDATA[Reply to [Solved] Dynamic Layout should be better then that what I&#x27;ve done on Tue, 17 Feb 2015 18:55:10 GMT]]></title><description><![CDATA[<p dir="auto">Sure? I had asked for help, not for a jester...</p>
]]></description><link>https://forum.qt.io/post/261919</link><guid isPermaLink="true">https://forum.qt.io/post/261919</guid><dc:creator><![CDATA[casisto]]></dc:creator><pubDate>Tue, 17 Feb 2015 18:55:10 GMT</pubDate></item></channel></rss>