<?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[Regarding buttons]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">i trying to develop a UI in Qml, where i am using column layout and row layout. the problem i am facing is with buttons, i have a column layout under which i have a row layout within that two rectangles, in the first rectangle i want to add few buttons in a column layout, when i try to add buttons, they are not adjusting to the given width and height, here is the following code :</p>
<pre><code>ColumnLayout{
            id: mainLayout
            anchors{
                left: parent.left
                leftMargin: 50
                horizontalCenter: parent.horizontalCenter
                verticalCenter: parent.verticalCenter
            }

            RowLayout{
                spacing: 50
                Commonrectangle{
                    id: phoneOptionsRect
                    rectColor: "blue"
                    rectHeight: phoneContentRect.height-70
                    rectWidth: phoneContentRect.width/4
                    ColumnLayout{
                        Button{
                            width: phoneOptionsRect.width
                            height: phoneOptionsRect.height/4
                            text: "Dial Pad"
                        }
                        Button{
                            width: phoneOptionsRect.width
                            height: phoneOptionsRect.height/4
                            text: "Dial Pad"
                        }
                    }

                }
                Commonrectangle{
                    id: phoneContentArea
                    rectColor: "steel blue"
                    rectHeight: phoneContentRect.height-70
                    rectWidth: (phoneContentRect.width/2)+100
                }
            }

            Commonrectangle{
                id: alphabetRect
                rectColor: "#258456"
                rectHeight: phoneContentRect.height/10
                rectWidth: (phoneContentRect.width)-100
            }
        }
</code></pre>
<p dir="auto">can anyone tell me what is wrong in the above code ?<br />
Thanks</p>
]]></description><link>https://forum.qt.io/topic/83170/regarding-buttons</link><generator>RSS for Node</generator><lastBuildDate>Tue, 04 Aug 2026 16:53:43 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/83170.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 11 Sep 2017 05:20:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Regarding buttons on Thu, 14 Sep 2017 05:28:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eeli-k">@<bdi>Eeli-K</bdi></a> Ok Thank you.. for the information :):)</p>
]]></description><link>https://forum.qt.io/post/415243</link><guid isPermaLink="true">https://forum.qt.io/post/415243</guid><dc:creator><![CDATA[Naveen_D]]></dc:creator><pubDate>Thu, 14 Sep 2017 05:28:12 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Wed, 13 Sep 2017 09:11:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/naveen_d">@<bdi>Naveen_D</bdi></a> To be honest it's not all very clear to me, either. But the basic reason is that using layouts and setting height/width explicitly are at odds with each other. There are of course rules to be found but there are several factors which make it complicated. There exist:</p>
<ul>
<li>implicitWidth/Height of each item which are hints for wanted w/h if nothing else is used</li>
<li>actual realized w/h of each item which you can try to set but may still be something different</li>
<li>x/y positioning coordinates of each item</li>
<li>anchors for each item</li>
<li>Layout.fillW/H</li>
<li>Layout.preferredW/H</li>
<li>Layout.minimum/maximumW/H</li>
</ul>
<p dir="auto">For the direct children of a layout you should not usually use width/height, x/y or anchors. Instead you use implicitW/H and Layout attached properties. The layout you use takes care of positioning, it's quite clear. Size is more complicated, but this is how I understand it: implicitW/H of an item (component) is used unless it's overridden by Layout attached properties. You should use either preferred... (and/or possibly minimum/maximum...) or fill.. but not both. That's it in short, but covering all cases and problems isn't possible in short space.</p>
<p dir="auto">Unfortunately there are many ways to do it wrong and there are so many of them it's not useful to try to understand why they don't work. Instead you just should learn what works and use that. Fortunately it's relatively easy and simple. Usually you just use Layout attached properties for direct children of a layout and anchors, implicitW/H and w/h for items which are not direct children of a layout. And remember that layouts are also items.</p>
]]></description><link>https://forum.qt.io/post/415089</link><guid isPermaLink="true">https://forum.qt.io/post/415089</guid><dc:creator><![CDATA[Eeli K]]></dc:creator><pubDate>Wed, 13 Sep 2017 09:11:19 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Wed, 13 Sep 2017 05:09:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eeli-k">@<bdi>Eeli-K</bdi></a> Thank you it is working, can you tell me when i was giving external width and height for the button why it was not working ?</p>
]]></description><link>https://forum.qt.io/post/415049</link><guid isPermaLink="true">https://forum.qt.io/post/415049</guid><dc:creator><![CDATA[Naveen_D]]></dc:creator><pubDate>Wed, 13 Sep 2017 05:09:51 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Tue, 12 Sep 2017 13:23:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/naveen_d">@<bdi>Naveen_D</bdi></a> Then add this inside rectangle1:</p>
<pre><code>ColumnLayout{
                    anchors.fill:parent // fill rectangle1
                    Button{Layout.fillWidth: true}
                    Button{Layout.fillWidth: true}
                    Item{Layout.fillHeight: true} // just a filler in case you want the buttons packed
                }
</code></pre>
<p dir="auto">Did you now understand how the Layout attached properties (Layout.preferred..., Layout.fill...) work?</p>
]]></description><link>https://forum.qt.io/post/414932</link><guid isPermaLink="true">https://forum.qt.io/post/414932</guid><dc:creator><![CDATA[Eeli K]]></dc:creator><pubDate>Tue, 12 Sep 2017 13:23:48 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Tue, 12 Sep 2017 12:23:40 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eeli-k">@<bdi>Eeli-K</bdi></a> Ya, it is working fine.. i am able to get the rectangles as expected.</p>
]]></description><link>https://forum.qt.io/post/414912</link><guid isPermaLink="true">https://forum.qt.io/post/414912</guid><dc:creator><![CDATA[Naveen_D]]></dc:creator><pubDate>Tue, 12 Sep 2017 12:23:40 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Tue, 12 Sep 2017 10:51:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/naveen_d">@<bdi>Naveen_D</bdi></a> said in <a href="/post/414885">Regarding buttons</a>:</p>
<blockquote>
<p dir="auto">i am developing it for a fixed size device screen.</p>
</blockquote>
<p dir="auto">This was important piece of information. If you know the screen/window size and it will never change, and your three-part top-level layout won't change either, it's OK to use manual sizing/positioning with the top-level rectangles. But layout objects work, too. If you have an embedded device with limited resources manual sizing/positioning is probably faster (though you should test it).</p>
<p dir="auto">However, you should decide which method to use in each place. You shouldn't do like this:</p>
<pre><code>RowLayout {
                    Rectangle{
                        id:myrect
                        width: mainrect.width/4
                        height: mainrect.height-70
</code></pre>
<p dir="auto">because setting width/height kind of deletes the purpose of a layout here. Either use a layout and attached properties or use manual size/position. When you need fixed size you should use Layout's attached properties. Try this top-level layout:</p>
<pre><code>ApplicationWindow {
    visible: true
    width: 640
    height: 480

    ColumnLayout {
        id: columnLayout
        anchors.fill: parent


        RowLayout {
            id: rowLayout

            Rectangle {
                id: rectangle1
                color: "blue"
                Layout.preferredWidth: 150 // or calculate
                Layout.fillHeight: true
            }

            Rectangle {
                id: rectangle2
                color: "steel blue"
                Layout.fillWidth: true
                Layout.fillHeight: true
            }
        }

        Rectangle {
            id: rectangle
            color: "grey"
            Layout.preferredHeight: 50 // or calculate
            Layout.fillWidth: true
        }
    }

}
</code></pre>
<p dir="auto">If it meets your needs, let's add the buttons in the next post.</p>
]]></description><link>https://forum.qt.io/post/414895</link><guid isPermaLink="true">https://forum.qt.io/post/414895</guid><dc:creator><![CDATA[Eeli K]]></dc:creator><pubDate>Tue, 12 Sep 2017 10:51:36 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Tue, 12 Sep 2017 09:59:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eeli-k">@<bdi>Eeli-K</bdi></a></p>
<blockquote>
<p dir="auto">do you want those buttons have fixed size as they have now? Should they be located in the top left corner of the app as they are now?</p>
</blockquote>
<p dir="auto">no.. the buttons should have the width same as the parent rectangle i.e blue rectangle height may vary since i have to add 4 to 5 buttons within that rectangle. so i was using the column layout there.</p>
<blockquote>
<p dir="auto">How about the blue rectangle? Should it have fixed width? And should the steel blue rectangle fill all the rest of the available width?</p>
</blockquote>
<p dir="auto">not mandatory that it should have fixed width but since i am developing it for a fixed size device screen i have made it as fixed and the other rectangle to fill the rest width.</p>
<p dir="auto">one more thing i want to add buttons in the bottom rectangle also, so i used the row layout, but same issue with height and width.</p>
]]></description><link>https://forum.qt.io/post/414885</link><guid isPermaLink="true">https://forum.qt.io/post/414885</guid><dc:creator><![CDATA[Naveen_D]]></dc:creator><pubDate>Tue, 12 Sep 2017 09:59:55 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Tue, 12 Sep 2017 08:54:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/naveen_d">@<bdi>Naveen_D</bdi></a> OK, now it's easier to find out the problems.</p>
<p dir="auto">First, the first top level Item is superfluous. It's of size 0 x 0 and doesn't have any properties or functionality within your app. It can be deleted.</p>
<p dir="auto">It's easy to see by resizing the main window horizontally and vertically that sizes of the objects don't work at all. If I interpret your code correctly you want to have three parts in it, the left (blue), right (steel blue) and bottom (grey) parts. The left part includes the buttons. So, if we don't talk about numbers at all but relative sizes and positions, do you want those buttons have fixed size as they have now? Should they be located in the top left corner of the app as they are now? How about the blue rectangle? Should it have fixed width? And should the steel blue rectangle fill all the rest of the available width?</p>
<p dir="auto">And similar questions for the height: what should the heights of the three parts be relative to each other and the main window?</p>
]]></description><link>https://forum.qt.io/post/414868</link><guid isPermaLink="true">https://forum.qt.io/post/414868</guid><dc:creator><![CDATA[Eeli K]]></dc:creator><pubDate>Tue, 12 Sep 2017 08:54:29 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Tue, 12 Sep 2017 06:17:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eeli-k">@<bdi>Eeli-K</bdi></a> ok sure i have created a separate example for that, here also same issue i am facing.</p>
<p dir="auto">i am adding column layout within <strong>id:myrect</strong> within which i am adding the buttons. but i am not able to make it fit within that rectangle with same width and different height.</p>
<pre><code>import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.1

Window {
    id: appWindow
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    Item{
        Rectangle {
            id: mainrect
            width: appWindow.width
            height:  appWindow.height
            color: "grey"

            ColumnLayout{
                anchors.fill: parent
                RowLayout {
                    Rectangle{
                        id:myrect
                        width: mainrect.width/4
                        height: mainrect.height-70
                        color: "blue"

                        ColumnLayout {
                            id:buttonColLayout
                            Button {
                                text: "dialpad"
                            }
                            Button {
                                text: "dialpad"
                            }
                        }
                    }
                    Rectangle{
                        id:myrect1
                        width: mainrect.width
                        height: mainrect.height-70
                        color: "steel blue"
                    }
                }
                Rectangle{
                    id: bottomRect
                    width: mainrect.width
                    height: mainrect.height/10
                }
            }
        }
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/414843</link><guid isPermaLink="true">https://forum.qt.io/post/414843</guid><dc:creator><![CDATA[Naveen_D]]></dc:creator><pubDate>Tue, 12 Sep 2017 06:17:38 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Mon, 11 Sep 2017 08:53:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/naveen_d">@<bdi>Naveen_D</bdi></a> If you still need more help, make your code a self-contained main.qml with the main window and add also phoneContentRect there. Then we can easily show step by step what must be done and why.</p>
<p dir="auto">(EDIT: and paste the code here :) )</p>
]]></description><link>https://forum.qt.io/post/414715</link><guid isPermaLink="true">https://forum.qt.io/post/414715</guid><dc:creator><![CDATA[Eeli K]]></dc:creator><pubDate>Mon, 11 Sep 2017 08:53:35 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Mon, 11 Sep 2017 07:26:54 GMT]]></title><description><![CDATA[<ul>
<li>make sure your topmost layout item fill the whole window (or component)</li>
<li>remove all lines where you set <strong>width</strong> and <strong>height</strong></li>
<li>if a component needs to stretch, use <strong>Layout.fillWidth: true</strong> or <strong>Layout.fillHeight: true</strong></li>
<li>you can tweak the results using other attached properties of <a href="http://doc.qt.io/qt-5/qml-qtquick-layouts-layout.html#attached-properties" target="_blank" rel="noopener noreferrer nofollow ugc">Layout</a></li>
</ul>
]]></description><link>https://forum.qt.io/post/414701</link><guid isPermaLink="true">https://forum.qt.io/post/414701</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Mon, 11 Sep 2017 07:26:54 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Mon, 11 Sep 2017 06:56:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> Sorry i didn't get, what i need to do<br />
When i use rectangle instead of button it will be adjusting to the width and height. but when i use button it won't.</p>
]]></description><link>https://forum.qt.io/post/414694</link><guid isPermaLink="true">https://forum.qt.io/post/414694</guid><dc:creator><![CDATA[Naveen_D]]></dc:creator><pubDate>Mon, 11 Sep 2017 06:56:05 GMT</pubDate></item><item><title><![CDATA[Reply to Regarding buttons on Mon, 11 Sep 2017 06:17:04 GMT]]></title><description><![CDATA[<p dir="auto">The point of having layouts is to get an UI that is adjusting automatically to fit the window size. Yet it looks like you are forcing fixed size for your components. Try to refrain from setting width and height, use the Layout attached properties instead (to specify which component should fill width etc.).</p>
]]></description><link>https://forum.qt.io/post/414686</link><guid isPermaLink="true">https://forum.qt.io/post/414686</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Mon, 11 Sep 2017 06:17:04 GMT</pubDate></item></channel></rss>