Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Slider in qml
Forum Updated to NodeBB v4.3 + New Features

[Solved] Slider in qml

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 4.9k 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.
  • H Offline
    H Offline
    Hannah24
    wrote on last edited by
    #1

    I have made a slider in qml. But I am getting an error, I have a little problem with the logic.
    here is my code

    @

    import QtQuick 1.1

    Rectangle{

    width:250
    height:250
    color: "grey"
    property alias maxValue_slider :text1.text
    property alias  minValue_slider :text2.text
    
    Rectangle {
        id: rectangle1
        x: 32
        y: 15
        width: m1.drag.maximumX+20
        height: 10
        color: "black"
    
    
        Rectangle {
            id: rectangle2
            width: 20
            height: 10
            radius:25
            color: "red"
            smooth:true
    
            MouseArea {
                id:m1
                anchors.fill:parent
                drag.target: rectangle2
                drag.axis: Drag.XAxis
                drag.minimumX:0
                drag.maximumX: maxValue_slider
                
                // Need some logic here..//
                onPositionChanged:  {slide.text=maxValue_slider-minValue_slider}
    
            }
        }
    
    }
    
    Rectangle {
        id: rectangle3
        x: 56
        y: 42
        width: 84
        height: 21
        color: "#ffffff"
    
    }
    
    TextEdit {
        id: text_edit1
        x: 60
        y: 43
        width: 80
        height: 20
        font.pixelSize: 12
    
        TextInput {
            id: slide
            x: 11
            y: 0
            width: 80
            height: 20
            text:text1.text
            font.pixelSize: 12
    
        }
    }
    
    Text {
        id: text1
        x: 20
        y: 31
        text: "100"
        font.pixelSize: 12
    }
    
    Text {
        id: text2
        x: 147
        y: 26
        text: "60"
        font.pixelSize: 12
    }
    

    }
    @

    I havebeen trying this for a long time. Thanks for your concern

    Hannah :)

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Hannah24
      wrote on last edited by
      #2

      I also tried to use the available Slider online.
      @
      Slider {
      orientation: Qt.Vertical
      maximumValue: 25
      stepSize: 1
      value: 25
      valueIndicatorVisible: true
      valueIndicatorText: "Volume"
      inverted: true
      }
      @

      But it gives an error "Slider is instantiated recursively"

      Edit: please use @ tags around code sections; Andre

      Hannah :)

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hannah24
        wrote on last edited by
        #3

        @import QtQuick 1.1
        Rectangle{

        width:250
        height:250
        color: "grey"
        property alias minValue_slider :text2.text
        property alias maxValue_slider :text1.text
        property int i:0
        property int k:0
        property int j:maxValue_slider-minValue_slider
        
        Rectangle {
            id: rectangle1
            x: 32
            y: 15
            width: 201
            height: 10
            color: "black"
            radius:5
        
        
        
            function value(minValue_sldier, maxValue_slider)
            {
                for (i=minValue_sldier;i<j;i++)
                k=i
              }
        
            Rectangle {
                id: rectangle2
                width: 20
                height: 10
                radius:25
                color: "red"
                smooth:true
        
        
                MouseArea {
                    anchors.fill:parent
                    drag.target: rectangle2
                    drag.axis: Drag.XAxis
                    drag.minimumX:0
                    drag.maximumX: rectangle1.width-10
                    onPositionChanged:  {text_input1.text=value(minValue_slider,maxValue_slider)}
        
                }
            }
        
        }
        
        Rectangle {
            id: rectangle3
            x: 56
            y: 42
            width: 84
            height: 21
            color: "#ffffff"
        
        }
        
        TextEdit {
            id: text_edit1
            x: 60
            y: 43
            width: 80
            height: 20
            font.pixelSize: 12
        
            TextInput {
                id: text_input1
                x: 11
                y: 0
                width: 80
                height: 20
                text:text1.text
                font.pixelSize: 12
        
            }
        }
        
        Text {
            id: text1
            x: 20
            y: 31
            text: "50"
            font.pixelSize: 12
        }
        
        Text {
            id: text2
            x: 203
            y: 31
            text: "10"
            font.pixelSize: 12
        }@
        

        I tried implementing it using a function vale but it says cant read variable value.. Could somebody help me

        Hannah :)

        1 Reply Last reply
        0
        • H Offline
          H Offline
          Hannah24
          wrote on last edited by
          #4

          I included

          @property int g:((maxValue_slider1)-(minValue_slider1))

          onPositionChanged: {text_input1.text=text1.text-rectangle2.x}@

          It worked perfectly-:), For those who are facing my problem

          Hannah :)

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Great that you managed to solve your issue. You marked your topic as 'Closed', which it is not. Only moderators can close topics, and do so only when really, really needed. I have changed the tag to 'solved' instead.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              Hannah24
              wrote on last edited by
              #6

              ok Andre I will follow it up.:) thanks

              Hannah :)

              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