<?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[Component does not integrate into the flow of a ColumnLayout]]></title><description><![CDATA[<p dir="auto">Hi!</p>
<p dir="auto">I build a TextInputField Component, which I would like to be able to simply integrate in the flow of a ColumnLayout. But a regular "static" Text above it is covered by the component, while a Button following the TextFieldComponent appears properly according to the spacing rules.</p>
<p dir="auto">(EDIT: I just found out that the button only follows correctly, because it adjust itself in relation to the Text component, but not to my custom component!)</p>
<p dir="auto">Can anybody help me find out, what am I doing wrong here? Thank you!</p>
<p dir="auto">TextInputField Component:</p>
<pre><code>import QtQuick 2.9
import QtQuick.Layouts 1.3

Item {
	id: rootItem

	property int w: 0
	property int h: 0
	property int xPos: 0
	property int yPos: 0
	property int padding: 6
	property string primaryColor: "midnightblue"
	property string primaryColorInverse: "lightsteelblue"
	property int rectBorderRadius: 2
	property int rectBorderWidth: 1
	property string placeholderText: "e.g. Tempo &amp; Rehearsal Marks"

	Rectangle {
		id: rect

		// x: rootItem.xPos
		// y: parent.y + parent.height + parent.spacing + parent.spacing/2
		width: rootItem.w
		height: rootItem.h

		color: rootItem.primaryColorInverse
		radius: rootItem.rectBorderRadius
		border {
			width: rootItem.rectBorderWidth
			color: rootItem.primaryColor
		}
		// antialiasing: false

		TextInput {
			id: txtInput
			y: rect.y + 8
			width: rect.w
			height: rect.h
			anchors {
				fill: rect
			}
			horizontalAlignment: rect.AlignHCenter
			// verticalAlignment: rect.AlignVCenter
			color: rootItem.primaryColor
			padding: rootItem.padding
			selectByMouse: true
			layer.enabled: true

			Text {
				text: rootItem.placeholderText
                                color: "teal"
				y: txtInput.y
				anchors {
					fill: txtInput
				}
				padding: txtInput.padding
                                visible: !txtInput.text &amp;&amp; !txtInput.activeFocus
			}
		}
	}
}

</code></pre>
<p dir="auto">Sample App (Musescore Plugin):</p>
<pre><code>import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import MuseScore 3.0

MuseScore {
	menuPath: "Plugins.Staff List Creator"
	description: "Descr"
	version: "0.1.0"
	id: root

	pluginType: "dock"
	dockArea: "right"
	width: 300
	height: 600
	requiresScore: true

	ColumnLayout {
		id: sourceStaffSelector
		anchors {
			left: root.left
			leftMargin: 5
			top: root.top
			topMargin: 5
			rightMargin: 5
		}
		spacing: 14
		width: 300

		Text {
			id: createStaffListSourceTitle
			text: qsTr("Enter a title for the new Staff List:")
			font {
				//pixelSize: 20
				pointSize: 14
				bold: true
			}
			anchors {
				fill: parent
			}
			color: "white"
			height: 28
		}

                // My Custom Component that should appear UNDER the above TEXT component...
		TextInputField {
			id: staffListTitle
			w: 300
			h: 28
		}

		Button {
			id: btnCreateStaffList
			text: qsTr("Create Staff List")
                        [...]
		}
	}
}
</code></pre>
<p dir="auto">Screenshot of the result (with remarks):<br />
<img src="https://ddgobkiprc33d.cloudfront.net/052ea1a2-ba36-4f1e-8081-27712adcdddf.jpg" alt="component.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/117941/component-does-not-integrate-into-the-flow-of-a-columnlayout</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 08:19:52 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/117941.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 12 Aug 2020 10:17:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Wed, 12 Aug 2020 10:36:04 GMT]]></title><description><![CDATA[<p dir="auto">There are multiple issues here:</p>
<ol>
<li>
<p dir="auto">You newer set any <code>width</code> or <code>height</code> for your component. <code>Item</code> has built-in <code>width</code> and <code>height</code> properties. So adding <code>w</code> and <code>h</code> is pointless (and since Layout does not know about them, it does not work), remove that or at least tie it to the concrete dimensions from <code>Item</code>.</p>
</li>
<li>
<p dir="auto">You are using <code>anchors</code> in your Text element, which is inside a Layout. This is an error - items inside layouts should not have any anchors. Qt warns about it in the console. If you want to modify positioning inside a layout, use the attached properties (<code>Layout.fillWidth</code>, <code>Layout.margins</code>, <code>Layout.alignment</code>, etc.).</p>
</li>
<li>
<p dir="auto">Components in Layout need to have some width or height set (anything other than <code>0</code>). In some cases, that means setting <code>height</code>, in others <code>implicitHeight</code> properties. If you want a component to stretch and fill all available space, use <code>Layout.fillWidth</code> or <code>Layout.fillHeight</code>.</p>
</li>
</ol>
]]></description><link>https://forum.qt.io/post/611844</link><guid isPermaLink="true">https://forum.qt.io/post/611844</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Wed, 12 Aug 2020 10:36:04 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Thu, 13 Aug 2020 09:19:43 GMT]]></title><description><![CDATA[<p dir="auto">When I define my custom Component, as suggested by <a class="plugin-mentions-user plugin-mentions-a" href="/user/grecko">@<bdi>GrecKo</bdi></a>, using "TextField {}" as root and not "Item {}", I get this error:</p>
<p dir="auto">Creating component failed<br />
line 47: Type CustomTextInputField unavailable</p>
<p dir="auto">// "CustomTextInputfield.qml"</p>
<pre><code>import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2

TextField {
	id: txtInput

	property int padding: 6
	property string primaryColor: "midnightblue"
	property string primaryColorInverse: "lightsteelblue"
	property int rectBorderRadius: 2
	property int rectBorderWidth: 1
	property string placeholderText: "e.g. Tempo &amp; Rehearsal Marks"

	// width: txtInput.width
	// height: txtInput.height
	color: txtInput.primaryColor
	padding: txtInput.padding

	selectByMouse: true
	layer.enabled: true

	background: Rectangle {
		color: txtInput.primaryColorInverse
		radius: txtInput.rectBorderRadius
		border {
				width: txtInput.rectBorderWidth
				color: txtInput.primaryColor
		}
	}

	Text {
		text: txtInput.placeholderText
		color: "#eeeeee"
		y: txtInput.y
		width: txtInput.width
		height: txtInput.height
		padding: txtInput.padding
		visible: !txtInput.text &amp;&amp; !txtInput.activeFocus
	}

}
</code></pre>
<p dir="auto">It does work, though, when I use "Item" around everything (and move the properties and adjust ids, of course).</p>
<p dir="auto">What am I misunderstanding here? Which mistake(s) do I make?</p>
]]></description><link>https://forum.qt.io/post/612049</link><guid isPermaLink="true">https://forum.qt.io/post/612049</guid><dc:creator><![CDATA[rowild]]></dc:creator><pubDate>Thu, 13 Aug 2020 09:19:43 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Thu, 13 Aug 2020 08:46:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> AHA!!! I think that turned on the lightbulb in my dark brain :-) Thank you very much!!</p>
]]></description><link>https://forum.qt.io/post/612036</link><guid isPermaLink="true">https://forum.qt.io/post/612036</guid><dc:creator><![CDATA[rowild]]></dc:creator><pubDate>Thu, 13 Aug 2020 08:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Thu, 13 Aug 2020 08:45:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rowild">@<bdi>rowild</bdi></a> said in <a href="/post/612028">Component does not integrate into the flow of a ColumnLayout</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> I have to ask something concerning the "anchors" attribute: In your second answer you say it is ok to "anchors.fill:parent" for the Rectangle, but in you first answer you mention that using "anchors" on a TextElement that lives within a Layout Component is a no-go. Do I understand you correctly on this or am I mixing up something? (I looked for docu talking about that, but haven't found anything yet - probably oversaw quite a bit. You don't happen to have a link to a place in the documentation that talks about that by any chance?)</p>
<p dir="auto">Thank you!</p>
</blockquote>
<p dir="auto">It may be confusing but it's not a mixup.</p>
<p dir="auto">In first post I was talking about components which are <em><strong>direct children</strong></em> of a <code>Layout</code> - there you cannot use <code>anchors</code>.</p>
<p dir="auto">In second post I was speaking of elements which were children of other items (not <code>Layout</code>) - there you can use <code>anchors</code> as much as you like :-)</p>
]]></description><link>https://forum.qt.io/post/612033</link><guid isPermaLink="true">https://forum.qt.io/post/612033</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 13 Aug 2020 08:45:30 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Thu, 13 Aug 2020 08:40:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a> I have to ask something concerning the "anchors" attribute: In your second answer you say it is ok to "anchors.fill:parent" for the Rectangle, but in you first answer you mention that using "anchors" on a TextElement that lives within a Layout Component is a no-go. Do I understand you correctly on this or am I mixing up something? (I looked for docu talking about that, but haven't found anything yet - probably oversaw quite a bit. You don't happen to have a link to a place in the documentation that talks about that by any chance?)</p>
<p dir="auto">Thank you!</p>
]]></description><link>https://forum.qt.io/post/612028</link><guid isPermaLink="true">https://forum.qt.io/post/612028</guid><dc:creator><![CDATA[rowild]]></dc:creator><pubDate>Thu, 13 Aug 2020 08:40:16 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Thu, 13 Aug 2020 08:06:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/grecko">@<bdi>GrecKo</bdi></a> Thank you so much for your valuable feedback!</p>
<p dir="auto">I am totally new to QML and "learned" the creation of custom components from a Youtube tutorial. There a "MyTextField" and a "MyButton" component are created the same way, meaning that "Item" is used as the base. Therefore I thought custom components must all start with "Item". It seems I am wrong! So thank you for opening up my perspective!</p>
<p dir="auto">I also read about the "implicit" attributes and played around with them. So far I didn't grasp the concept, my tries didn't result in anything that gave me the "aha!" experience - they did simply nothing... I assume these values can be compared somewhat to CSS's flexbox features, where - in case there are more objects taking up the space of their parent - a given width or height won't shrink any further, if "flex-shrink: 0" is set?</p>
<p dir="auto">I will work through what you posted and will report back.</p>
<p dir="auto">Again, this is a lot of help and an excellent forum, so thanks to all of you for helping me out here!<br />
Have a good day!</p>
]]></description><link>https://forum.qt.io/post/612012</link><guid isPermaLink="true">https://forum.qt.io/post/612012</guid><dc:creator><![CDATA[rowild]]></dc:creator><pubDate>Thu, 13 Aug 2020 08:06:42 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Wed, 12 Aug 2020 12:58:55 GMT]]></title><description><![CDATA[<p dir="auto">Your custom component look unnecessarily complicated.</p>
<p dir="auto">Why do you use a Item as the root object, and then fill it with a Rectangle?<br />
You could have just used a Rectangle as root.</p>
<p dir="auto">Building on top of a TextField looks to be easier (it seems you are just customizing the background and placeholder label)</p>
<pre><code>TextField {
    id: root
    property string primaryColor: "midnightblue"     
    property string primaryColorInverse: "lightsteelblue"     
    property int rectBorderRadius: 2     
    property int rectBorderWidth: 1

    background: Rectangle {
        color: rootItem.primaryColorInverse
        radius: rootItem.rectBorderRadius
        border {
            width: rootItem.rectBorderWidth
            color: rootItem.primaryColor
        }
    }
    Text {
        text: root.placeholderText
        // other stuff for your placeholder (see here for inspiration : https://github.com/qt/qtquickcontrols2/blob/dev/src/imports/controls/TextField.qml )
     }
}
</code></pre>
<p dir="auto">A lot of properties are missing from your handmade solution, for example you don't set any implicitWidth or implicitHeight (which are used by layouts). Even simple stuff like the text of the TextInput is not accessible from outside.</p>
<p dir="auto">An alternative from subclassing TextField would be to provide your own QtQuick Controls 2 style : <a href="https://doc.qt.io/archives/qt-5.11/qtquickcontrols2-customize.html#creating-a-custom-style" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/archives/qt-5.11/qtquickcontrols2-customize.html#creating-a-custom-style</a></p>
]]></description><link>https://forum.qt.io/post/611865</link><guid isPermaLink="true">https://forum.qt.io/post/611865</guid><dc:creator><![CDATA[GrecKo]]></dc:creator><pubDate>Wed, 12 Aug 2020 12:58:55 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Wed, 12 Aug 2020 11:26:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rowild">@<bdi>rowild</bdi></a> said in <a href="/post/611847">Component does not integrate into the flow of a ColumnLayout</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a><br />
You say that I do not set any width and height in my component. If I understood you well, then I have to explicitly set the "width" and "height" properties on "Item"? This is what I did and - voilà! - it works! (I also removed the anchors you mentioned.)</p>
</blockquote>
<p dir="auto">Nice!</p>
<blockquote>
<pre><code>Item {
  id: rootItem
  property int w: 0
  property int h: 0
  width: w
  height: h
  [...]
</code></pre>
</blockquote>
<p dir="auto">That's OK. But looking at the code, I'd say you don't need <code>property int w</code> at all. Just use <code>width</code>.</p>
<p dir="auto">Then in child items (Rectangle, Text etc.) you don't need to do:</p>
<pre><code>width: rootItem.w
height: rootItem.h
</code></pre>
<p dir="auto">It's enough to call <code>anchors.fill: parent</code>.</p>
<blockquote>
<p dir="auto">However: what do you mean by "...or at least tie it to the concrete dimensions from Item"? What would that look like?</p>
</blockquote>
<p dir="auto">Exactly what you did :-)</p>
<blockquote>
<p dir="auto">Thank you again! Much appreciated! :-)</p>
</blockquote>
<p dir="auto">Happy coding :-)</p>
]]></description><link>https://forum.qt.io/post/611849</link><guid isPermaLink="true">https://forum.qt.io/post/611849</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Wed, 12 Aug 2020 11:26:44 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Wed, 12 Aug 2020 11:22:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a></p>
<p dir="auto">Thank you very much for your quick response!</p>
<p dir="auto">First, I should mention that I cannot use Qt Creator, because there is currently no way to import Musescore. (If anybody does, that would be awesome!)<br />
So I use VScode and the integrated IDE of Musescore, which is very, very limited. Also, when it comes to external files, Musescore has to be restarted as soon as there have been changes, since Musescore does not recognise that a dependency was changed (and deleting the .qmlc won't work either).<br />
I am not sure, though, if this is the reason, why I do not see the errors in the console you are mentioning (about using anchors within Layouts). I have to investigate...</p>
<p dir="auto">You say that I do not set any width and height in my component. If I understood you well, then I have to explicitly set the "width" and "height" properties on "Item"? This is what I did and - voilà! - it works! (I also removed the anchors you mentioned.)</p>
<pre><code>Item {
  id: rootItem
  property int w: 0
  property int h: 0
  width: w
  height: h
  [...]
</code></pre>
<p dir="auto">However: what do you mean by "...or at least tie it to the concrete dimensions from Item"? What would that look like?</p>
<p dir="auto">Thank you again! Much appreciated! :-)</p>
]]></description><link>https://forum.qt.io/post/611847</link><guid isPermaLink="true">https://forum.qt.io/post/611847</guid><dc:creator><![CDATA[rowild]]></dc:creator><pubDate>Wed, 12 Aug 2020 11:22:05 GMT</pubDate></item><item><title><![CDATA[Reply to Component does not integrate into the flow of a ColumnLayout on Wed, 12 Aug 2020 10:36:04 GMT]]></title><description><![CDATA[<p dir="auto">There are multiple issues here:</p>
<ol>
<li>
<p dir="auto">You newer set any <code>width</code> or <code>height</code> for your component. <code>Item</code> has built-in <code>width</code> and <code>height</code> properties. So adding <code>w</code> and <code>h</code> is pointless (and since Layout does not know about them, it does not work), remove that or at least tie it to the concrete dimensions from <code>Item</code>.</p>
</li>
<li>
<p dir="auto">You are using <code>anchors</code> in your Text element, which is inside a Layout. This is an error - items inside layouts should not have any anchors. Qt warns about it in the console. If you want to modify positioning inside a layout, use the attached properties (<code>Layout.fillWidth</code>, <code>Layout.margins</code>, <code>Layout.alignment</code>, etc.).</p>
</li>
<li>
<p dir="auto">Components in Layout need to have some width or height set (anything other than <code>0</code>). In some cases, that means setting <code>height</code>, in others <code>implicitHeight</code> properties. If you want a component to stretch and fill all available space, use <code>Layout.fillWidth</code> or <code>Layout.fillHeight</code>.</p>
</li>
</ol>
]]></description><link>https://forum.qt.io/post/611844</link><guid isPermaLink="true">https://forum.qt.io/post/611844</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Wed, 12 Aug 2020 10:36:04 GMT</pubDate></item></channel></rss>