Qml TextField可以';不能在RowLayout中调整大小

Qml TextField可以';不能在RowLayout中调整大小,qml,qt5,qtquick2,qtquickcontrols,Qml,Qt5,Qtquick2,Qtquickcontrols,将TextField放入RowLayout后,我无法再调整TextField的大小。我试图为TextField设置anchors以填充RowLayout的左侧及其中心,使其成为RowLayout宽度的一半,但它变得比它的一半大 现在我正试图将文本字段的宽度绑定到行布局的宽度,但元素仍然没有调整大小。当我将TextField从其父项中取出时,它的大小调整得很好。这是Qt的错误还是我忘记了什么 这是我得到的照片: 正如@KernelPanic所说,我在TextFields上使用了Layout.fi

TextField
放入
RowLayout
后,我无法再调整
TextField
的大小。我试图为
TextField
设置
anchor
s以填充
RowLayout
的左侧及其中心,使其成为
RowLayout
宽度的一半,但它变得比它的一半大

现在我正试图将
文本字段的
宽度
绑定到
行布局的
宽度
,但元素仍然没有调整大小。当我将
TextField
从其父项中取出时,它的大小调整得很好。这是
Qt
的错误还是我忘记了什么

这是我得到的照片:


正如@KernelPanic所说,我在
TextField
s上使用了
Layout.fillWidth
,一切都开始正常工作

根据Qt文件:

如果此属性为true,则项目将尽可能宽,同时遵守给定的约束。如果该属性为false,则该项的固定宽度将设置为首选宽度。默认值为false,布局本身除外,默认值为true

尊重给定的约束条件


这正是我所需要的

您没有考虑的间距
,默认情况下,间距不是零。另外,
anchors.fill:parent
布局:像那样设置
x
/
y
是个糟糕的设计。写下你自己的答案。我的RowLayout/ColumnLayout规则是不使用宽度/高度。仅使用implicitWidth/implicitHeight、Layout.fillWidth、Layout.preferredWidth、Layout.minimumWidth等。最后一件事:当RowLayout真的对您不利时,将其包装成一个项目。
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.2

ApplicationWindow {
    visible: true
    width: 210
    height: 160

    RowLayout {
        x: 15
        y: 21
        width: 181
        height: 23

        TextField {
            id: first
            width: parent.width /2
            height: parent.height
        }

        TextField {
            id: second
            width: parent.width /2
            height: parent.height
        }
    }

    TextField {
        id: result
        x: 15
        y: 55
        width: 181
        height: 23
        placeholderText: qsTr("Result")
    }
}