无法在 RowLayout 中调整 TextField 的大小
TextField can't be resized within RowLayout
将 TextField
放入 RowLayout
后,我无法再调整 TextField
的大小。我尝试为 TextField
设置 anchor
s 以填充 RowLayout
的左侧及其中心,使其成为 RowLayout
的 width
的一半,但它变成了只比它的一半大。
现在我正在尝试将 TextField
的 width
绑定到 RowLayout
的 width
,但元素仍然没有调整大小。当我从其父级中取出 TextField
时,它会很好地调整大小。这是 Qt
的错误还是我忘记了什么?
这是我得到的照片:
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")
}
}
正如@KernelPanic 所说,我在 TextField
上使用了 Layout.fillWidth
,一切开始正常工作。
根据 Qt 文档:
If this property is true, the item will be as wide as possible while respecting the given constraints. If the property is false, the item will have a fixed width set to the preferred width. The default is false, except for layouts themselves, which default to true.
和
respecting the given constraints
正是我所需要的
将 TextField
放入 RowLayout
后,我无法再调整 TextField
的大小。我尝试为 TextField
设置 anchor
s 以填充 RowLayout
的左侧及其中心,使其成为 RowLayout
的 width
的一半,但它变成了只比它的一半大。
现在我正在尝试将 TextField
的 width
绑定到 RowLayout
的 width
,但元素仍然没有调整大小。当我从其父级中取出 TextField
时,它会很好地调整大小。这是 Qt
的错误还是我忘记了什么?
这是我得到的照片:
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")
}
}
正如@KernelPanic 所说,我在 TextField
上使用了 Layout.fillWidth
,一切开始正常工作。
根据 Qt 文档:
If this property is true, the item will be as wide as possible while respecting the given constraints. If the property is false, the item will have a fixed width set to the preferred width. The default is false, except for layouts themselves, which default to true.
和
respecting the given constraints
正是我所需要的