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. [solved] Margins on sliders doesn't work
QtWS25 Last Chance

[solved] Margins on sliders doesn't work

Scheduled Pinned Locked Moved QML and Qt Quick
slidersmargins
4 Posts 2 Posters 1.5k Views
  • 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.
  • B Offline
    B Offline
    bam500
    wrote on 25 Jan 2016, 10:01 last edited by bam500
    #1

    Hi,

    I'm trying to display three sliders in my app (one above the other). I set their position using anchors. As they're too close to eachother I'm using top and bottom margins on the middle slider so that they appear less close. But it doesn't seem to work as I change the value of the margins :

    Rectangle
            {
                id: rectanglePourcentageLiquide
                width: centerArea.width*1/2
                height: centerArea.height*1/2
                anchors.top: rectangleVueLaterale.bottom
                anchors.left: rectangleVueLaterale.left
                color: "transparent"
    
                // Left tank
                Slider
                {
                    id: sliderLeft
                    width: centerArea.width*1/2 - centerArea.width*1/10
                    anchors.top: rectangleVueLaterale.bottom
                    anchors.bottom: sliderMiddle.top
                    anchors.horizontalCenter: parent.horizontalCenter
                    minimumValue: 0
                    maximumValue: 100
                    stepSize: 1
                    onValueChanged: { 
                    }
                }
    
                // Middle tank
                Slider
                {
                    id: sliderMiddle
                    width: centerArea.width*1/2 - centerArea.width*1/10
                    anchors.centerIn: parent
                    anchors.topMargin: 100
                    anchors.bottomMargin: 100
                    minimumValue: 0
                    maximumValue: 100
                    stepSize: 1
                    onValueChanged: { }
                }
    
                // Right tank
                Slider
                {
                    id: sliderRight
                    width: centerArea.width*1/2 - centerArea.width*1/10
                    anchors.top: sliderMiddle.bottom
                    anchors.horizontalCenter: parent.horizontalCenter
                    minimumValue: 0
                    maximumValue: 100
                    stepSize: 1
                    onValueChanged: { 
                    }
                }
    
    

    Do margins work with sliders ? If not, is there another way to keep them away ?

    Regards,

    1 Reply Last reply
    0
    • L Offline
      L Offline
      literA2
      wrote on 25 Jan 2016, 11:42 last edited by literA2
      #2

      I think it would be easy if you make use of Column to display them vertically and use its spacing property.

           Item    // use Item as container since you only set its color as transparent
           {
              id: rectanglePourcentageLiquide
              width: centerArea.width*0.5
              height: centerArea.height*0.5
              anchors {
                 top: rectangleVueLaterale.bottom
                 left: rectangleVueLaterale.left
              }
      
              Column {
                 id: sliderColumn
                 anchors {
                     verticalCenter: parent.verticalCenter
                     left: parent.left
                     leftMargin: centerArea.width*0.05
                     right: parent.right
                     rightMargin: centerArea.width*0.05
                  }
                 spacing: 100
      
              // Left tank
              Slider
              {
                  id: sliderLeft
                  anchors { left: parent.left; right: parent.right }
                  minimumValue: 0
                  maximumValue: 100
                  stepSize: 1
                  onValueChanged: { 
                  }
              }
      
              // Middle tank
              Slider
              {
                  id: sliderMiddle
                  anchors { left: parent.left; right: parent.right }
                  minimumValue: 0
                  maximumValue: 100
                  stepSize: 1
                  onValueChanged: { }
              }
      
              // Right tank
              Slider
              {
                  id: sliderRight
                  anchors { left: parent.left; right: parent.right }
                  minimumValue: 0
                  maximumValue: 100
                  stepSize: 1
                  onValueChanged: { 
                  }
              }
          }
      }
      

      In your code, the reason why the margins didn't work because you've anchored the Middle tank on the center of the parent.

      Hope this helps. ;)

      1 Reply Last reply
      1
      • B Offline
        B Offline
        bam500
        wrote on 25 Jan 2016, 14:06 last edited by bam500
        #3

        Thank you literA2,

        It really helped. What if I want to add TexteLabel on the right of each Slider ? Do I have to encapsulate each Slider + TexteLabel with an Item or I have to use a Grid to have two columns ?

        Regards,

        L 1 Reply Last reply 25 Jan 2016, 14:26
        0
        • B bam500
          25 Jan 2016, 14:06

          Thank you literA2,

          It really helped. What if I want to add TexteLabel on the right of each Slider ? Do I have to encapsulate each Slider + TexteLabel with an Item or I have to use a Grid to have two columns ?

          Regards,

          L Offline
          L Offline
          literA2
          wrote on 25 Jan 2016, 14:26 last edited by
          #4

          @bam500 Yes, using GridLayout is an option so that the vertical alignment of the texts are equal.

          1 Reply Last reply
          1

          1/4

          25 Jan 2016, 10:01

          • Login

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