4

After putting TextField in RowLayout I can't resize the TextField anymore. I tried to set anchors for TextField to fill left side of RowLayout and its center to make it the half of width of the RowLayout but it becames just bigger than the half of it.

Right now I'm trying to bind the width of the TextField to that of RowLayout but still the element just doesn't resize. When I take TextField out of its parent it resizes fine. Is this a bug of Qt or did I forget something?

Here is the pic of what I get:

enter image description here

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")
    }
}
BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Thelastpolaris
  • 341
  • 4
  • 12
  • You are not considering `spacing` which by default isn't zero. Also, `anchors.fill: parent` the layout: setting `x`/`y` like that is bad design. – BaCaRoZzo Jan 23 '16 at 10:41
  • 1
    Write your own answer. My rule for RowLayout/ColumnLayout is to not to use width/height. Only use implicitWidth/implicitHeight, Layout.fillWidth, Layout.preferredWidth, Layout.minimumWidth, etc. – Velkan Jan 23 '16 at 17:16
  • Last thing: when RowLayout really-really turns against you, wrap it into an Item. – Velkan Jan 23 '16 at 20:20

1 Answers1

4

As @KernelPanic said, I used Layout.fillWidth on TextFields and everything began to work fine.

According to Qt documentation:

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.

And

respecting the given constraints

was exactly what I needed

Thelastpolaris
  • 341
  • 4
  • 12