archqt
16th June 2014, 23:48
Hi,
i did a component that extends to whole size of parent, but it doesn't work when used in a window. If i use it with qmlscene it works but nope on this example. To explain the problem here is my code :
Fist example with component in separate files
File : SelectValue2
import QtQuick 2.2
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
Rectangle {
id: rectangle1
property real value : 0
property alias text : texte.text
width: 400
height: 200
visible: true
Text {
id: texte
text: "o2"
anchors.margins: 5
anchors.left: parent.left
font.pixelSize: 12
width: 30
}
TextInput {
id: an
text: value
font.pixelSize: 12
anchors.margins: 5
anchors.rightMargin: 0
anchors.left: texte.right
clip: true
width: 4*font.pixelSize
validator: DoubleValidator {bottom: -10; top: 10; decimals: 2}
Keys.onReturnPressed: value=parseFloat(text)
}
Slider {
id: slider
minimumValue: -10
maximumValue: 10
stepSize: 0.1
value: value
anchors.margins: 5
anchors.bottom: parent.bottom
anchors.top: parent.top
anchors.left: an.right
anchors.right: parent.right
onValueChanged: parent.value=value==null?0:Math.floor(value*100)/100
}
onValueChanged: slider.value=value
}
And the main that use it :
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
ApplicationWindow {
id: applicationWindow1
visible: true
width: 640
height: 480
ColumnLayout {
id: grid1
y: 28
anchors.fill: parent
anchors.leftMargin: 5
anchors.rightMargin: 5
onWidthChanged: console.log("Column : "+width)
Text { text: grid1.width
}
SelectValue2 {text: "ok"; value: 20; height: 20; width: 800}
SelectValue2 {text: "ok"; value: 20; height: 20; width: grid1.width} // doesn't work why??
SelectValue2 {text: "ok"; value: 20; height: 20}
}
}
Here is the result :
10425
As you can see the size is only made at begining (except for the second one) but after it doesn't change. What is wrong with that code ? If someone can help me please. thanks
Sincerely
i did a component that extends to whole size of parent, but it doesn't work when used in a window. If i use it with qmlscene it works but nope on this example. To explain the problem here is my code :
Fist example with component in separate files
File : SelectValue2
import QtQuick 2.2
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
Rectangle {
id: rectangle1
property real value : 0
property alias text : texte.text
width: 400
height: 200
visible: true
Text {
id: texte
text: "o2"
anchors.margins: 5
anchors.left: parent.left
font.pixelSize: 12
width: 30
}
TextInput {
id: an
text: value
font.pixelSize: 12
anchors.margins: 5
anchors.rightMargin: 0
anchors.left: texte.right
clip: true
width: 4*font.pixelSize
validator: DoubleValidator {bottom: -10; top: 10; decimals: 2}
Keys.onReturnPressed: value=parseFloat(text)
}
Slider {
id: slider
minimumValue: -10
maximumValue: 10
stepSize: 0.1
value: value
anchors.margins: 5
anchors.bottom: parent.bottom
anchors.top: parent.top
anchors.left: an.right
anchors.right: parent.right
onValueChanged: parent.value=value==null?0:Math.floor(value*100)/100
}
onValueChanged: slider.value=value
}
And the main that use it :
import QtQuick 2.2
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
ApplicationWindow {
id: applicationWindow1
visible: true
width: 640
height: 480
ColumnLayout {
id: grid1
y: 28
anchors.fill: parent
anchors.leftMargin: 5
anchors.rightMargin: 5
onWidthChanged: console.log("Column : "+width)
Text { text: grid1.width
}
SelectValue2 {text: "ok"; value: 20; height: 20; width: 800}
SelectValue2 {text: "ok"; value: 20; height: 20; width: grid1.width} // doesn't work why??
SelectValue2 {text: "ok"; value: 20; height: 20}
}
}
Here is the result :
10425
As you can see the size is only made at begining (except for the second one) but after it doesn't change. What is wrong with that code ? If someone can help me please. thanks
Sincerely