Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Component works when duplicated but doesn't work if in single file

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 795 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    archqt
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved