Немогу понять почему обьект не "растягивается"?
Задал два квадрата и привязал размер текста к размеру квадрата
Только вот в первом квадрате (бирюзовом) текст и ввод не растягиваются

Вот не знаю как сделать динамическую подстройку элементов ввода и текста
вот код :
import QtQuick 2.2
import QtQuick.Window 2.12
import QtQuick.Layouts 1.4
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Rectangle {
id: rectangle
color: "#89cdf1"
x: parent.width/100;
y:parent.height/10;
width: parent.width/4
height: parent.height/1.2
Layout.alignment: Qt.AlignRight
anchors
{
leftMargin: 10
rightMargin: 10
bottomMargin: 10
}
Grid{
id: gridLayout
x:0
y:0
rows: 2
columns: 2
// anchors.centerIn: parent
columnSpacing: 10
rowSpacing: 10
Text {
id:text1
color: "#00000f"
text: "ширина1:"
font.family: "Helvetica"
font.pixelSize: parent.width /10;
}
// Область с TextInput
Rectangle {
id:rectangle2
Layout.fillWidth: true
Layout.fillHeight: true
color: "white"
width: parent.width /2;
height: parent.height /3;
TextInput {
id: textInput3
color: "#151515";
selectionColor: "green"
font.pixelSize: parent.width /10;
font.bold: true
width: parent.width/3;
height: parent.height /3;
maximumLength: 8
anchors.centerIn: parent
focus: true
validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ } //ввод только чисел !!
anchors.fill: parent
// horizontalAlignment: Text.AlignHCenter
// verticalAlignment: Text.AlignVCenter
cursorVisible : true
// /* По нажатию клавиши Enter передаём информацию
// * из TextInput в элемент ListView
// * */
}
}
Text {
id:text3
color: "#00000f"
text: "ширина2:"
font.family: "Helvetica"
// font.pointSize: parent.width/(4*4);
}
// Область с TextInput
Rectangle {
id:rectangle3
Layout.fillWidth: true
Layout.fillHeight: true
color: "white"
width: parent.width /2;
height: parent.height /3;
TextInput {
id: textInput4
color: "#151515";
selectionColor: "green"
font.pixelSize: parent.width /10;
font.bold: true
width: parent.width/3;
height: parent.height /3;
maximumLength: 8
anchors.centerIn: parent
focus: true
validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ } //ввод только чисел !!
anchors.fill: parent
// horizontalAlignment: Text.AlignHCenter
// verticalAlignment: Text.AlignVCenter
cursorVisible : true
// /* По нажатию клавиши Enter передаём информацию
// * из TextInput в элемент ListView
// * */
}
}
}
}
Rectangle {
id: rectangle1
color: "#5555f1"
x:(parent.width - ((parent.width/4)*1.05));
y:parent.height/10;
width: parent.width/4
height: parent.height/1.2
// Layout.alignment: Qt.AlignLeft
anchors
{
leftMargin: 10
rightMargin: 10
bottomMargin: 10
}
Text {
// (1) identifier
id: thisLabel
// (2) set x- and y-position
x: 24; y: 16
// (3) bind height to 2 * width
height: 2 * width
// (4) custom property
property int times: 24
// (5) property alias
property alias anotherTimes: thisLabel.times
// (6) set text appended by value
text: "Greetings " + times
// (7) font is a grouped property
font.family: "Ubuntu"
font.pixelSize: parent.width /10
// (8) KeyNavigation is an attached property
KeyNavigation.tab: otherLabel
// (9) signal handler for property changes
onHeightChanged: console.log('height:', height)
// focus is need to receive key events
focus: true;
// change color based on focus value
color: focus?"red":"black"
}
}
}
Ответы (1 шт):
Автор решения: timob256
→ Ссылка
Спасибо @Croessmah
в общем добавил рамер грида и всё стало меняться
import QtQuick 2.2
import QtQuick.Window 2.12
import QtQuick.Layouts 1.4
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Rectangle {
id: rectangle
color: "#89cdf1"
x: parent.width/100;
y:parent.height/10;
width: parent.width/4
height: parent.height/1.2
Layout.alignment: Qt.AlignRight
anchors
{
leftMargin: 10
rightMargin: 10
bottomMargin: 10
}
Grid{
id: gridLayout
x:0
y:10;
width: parent.width;
height: parent.height/3
rows: 2
columns: 2
// anchors.centerIn: parent
columnSpacing: 10
rowSpacing: 10
Text {
id:text1
color: "#00000f"
text: "ширина1:"
font.family: "Helvetica"
font.pixelSize: parent.width/10;
}
// Область с TextInput
Rectangle {
id:rectangle2
y: parent.height /100;
Layout.fillWidth: true
Layout.fillHeight: true
color: "white"
width: parent.width /3;
height: parent.height /7;
TextInput {
id: textInput3
color: "#151515";
selectionColor: "green"
font.pixelSize: parent.width /5;
font.bold: true
width: parent.width/3;
height: parent.height /3;
maximumLength: 8
anchors.centerIn: parent
focus: true
validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ } //ввод только чисел !!
anchors.fill: parent
// horizontalAlignment: Text.AlignHCenter
// verticalAlignment: Text.AlignVCenter
cursorVisible : true
// /* По нажатию клавиши Enter передаём информацию
// * из TextInput в элемент ListView
// * */
}
}
Text {
id:text3
color: "#00000f"
text: "ширина2:"
font.family: "Helvetica"
// font.pointSize: parent.width/(4*4);
font.pixelSize: parent.width /10;
}
// Область с TextInput
Rectangle {
id:rectangle3
y:200; // не работает
x:100; // не работает
Layout.fillWidth: true
Layout.fillHeight: true
color: "white"
width: parent.width /3;
height: parent.height /7; // 10
TextInput {
id: textInput4
y: 20;
color: "#151515";
selectionColor: "green"
font.pixelSize: parent.width /5;
font.bold: true
width: parent.width/3;
height: parent.height /3;
maximumLength: 8
anchors.centerIn: parent
focus: true
validator : RegExpValidator { regExp : /[0-9]+\.[0-9]+/ } //ввод только чисел !!
anchors.fill: parent
// horizontalAlignment: Text.AlignHCenter
// verticalAlignment: Text.AlignVCenter
cursorVisible : true
// /* По нажатию клавиши Enter передаём информацию
// * из TextInput в элемент ListView
// * */
}
}
}
}
Rectangle {
id: rectangle1
color: "#5555f1"
x:(parent.width - ((parent.width/4)*1.05));
y:parent.height/10;
width: parent.width/4
height: parent.height/1.2
// Layout.alignment: Qt.AlignLeft
anchors
{
leftMargin: 10
rightMargin: 10
bottomMargin: 10
}
Text {
// (1) identifier
id: thisLabel
// (2) set x- and y-position
x: 24; y: 16
// (3) bind height to 2 * width
height: 2 * width
// (4) custom property
property int times: 24
// (5) property alias
property alias anotherTimes: thisLabel.times
// (6) set text appended by value
text: "Greetings " + times
// (7) font is a grouped property
font.family: "Ubuntu"
font.pixelSize: parent.width /10
// (8) KeyNavigation is an attached property
KeyNavigation.tab: otherLabel
// (9) signal handler for property changes
onHeightChanged: console.log('height:', height)
// focus is need to receive key events
focus: true;
// change color based on focus value
color: focus?"red":"black"
}
}
}


