Component works when duplicated but doesn't work if in single file



  • Hi,
    i did this component (file : SelectValue.qml)
    @import QtQuick 2.2
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 1.1

    Rectangle {
    property real value : 0
    property alias text : texte.text

    height: parent.height
    width: parent.width
    RowLayout {
        anchors.fill: parent
        Text {
            id: texte
            font.pixelSize: 12
            Layout.minimumWidth: 30
            Layout.fillHeight: true
        }
    
        TextInput {
            id: an
            text: value
            clip: true
            Layout.minimumWidth: 30
            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
            Layout.minimumWidth: 30
            Layout.fillWidth: true
            //Layout.fillHeight: true
            onValueChanged: parent.parent.value=value==null?0:Math.floor(value*100)/100
        }
    }
    onValueChanged: slider.value=value
    

    }
    @

    And i did this file
    @import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtQuick.Layouts 1.1

    ApplicationWindow {
    id: applicationWindow1

    ColumnLayout {
        id: grid1
        y: 28
        anchors.fill: parent
        anchors.leftMargin: 5
        anchors.rightMargin: 5
        SelectValue {text: "ok"; value: 20; height: 20}
        SelectValue {text: "ok"; value: 20; height: 20}
        SelectValue {text: "ok"; value: 20; height: 20}
    }
    

    }
    @

    If you do this, you will see that the slider gains the size when you change the window size but after it came down to smaller size if you change the value.
    If you copy the first file three times (you change id) then it works ?
    why ?
    Thanks
    Sincerely



  • I understood that you would like to increase the size of slider when the window size increases. If that is the case you need to put the following line for every component creation.

    SelectValue {Layout.fillWidth: true;

    If this is not your case, please do let me know what are you trying to achieve. I can help you on that.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.