Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Regarding Slider in QML
Qt 6.12 LTS is out! See what's new in the release blog

Regarding Slider in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
14 Posts 4 Posters 9.3k 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.
  • ibiaI Offline
    ibiaI Offline
    ibia
    wrote on last edited by
    #4

    Yes the slider handle updates when I change the value. But to test your code, I replaced the applicationWindow.width with 600.

    I think that you should create a new project and put in it only the code above to test your code. I imported QtQuick.Controls and QtQuick.Controls.Styles.

    Naveen_DN 1 Reply Last reply
    0
    • ibiaI ibia

      Yes the slider handle updates when I change the value. But to test your code, I replaced the applicationWindow.width with 600.

      I think that you should create a new project and put in it only the code above to test your code. I imported QtQuick.Controls and QtQuick.Controls.Styles.

      Naveen_DN Offline
      Naveen_DN Offline
      Naveen_D
      wrote on last edited by
      #5

      @ibia
      I am running it separately only creating new project, but in my case its not updating. i have replaced applicationWindow.width with 300 as shown below.

      import QtQuick 2.5
      import QtQuick.Window 2.2
      import QtQuick.Extras 1.4
      import QtQuick.Controls.Styles 1.4
      import QtQuick.Controls 1.4
      
      Window {
          id: root
          visible: true
          width: 640
          height: 480
      
          Slider {
              id: theSlider
      
              property alias sliderWidth: theSlider.width
              property alias sliderValue: theSlider.value
      
              width:300
              maximumValue: 100
              minimumValue: 50
              value:minimumValue
              updateValueWhileDragging : true
              style: SliderStyle {
                  groove:  Rectangle {
                      id: grooveMainrect
                      height: 8
                      radius: 5
                      color: "#847878"
                      Rectangle {
                          id: groovechildrect
                          width: (parent.width * theSlider.value)/theSlider.maximumValue
                          height: parent.height
                          color: Qt.lighter("#7ea6d6", 1.2)
                          radius: parent.radius
                      }
                  }
                  handle: Rectangle {
                      id:handlemainrect
                      height: 25
                      width: 25
                      radius: width/2
                      color: Qt.lighter("#7ea6d6", 1.2)
                      Rectangle {
                          id: handlechildrect
                          width: parent.width/3
                          height: parent.height/3
                          anchors.centerIn: parent
                          color: "#ffffff"
                          radius: width/2
                      }
                  }
              }
          }
      }
      

      Naveen_D

      1 Reply Last reply
      0
      • ibiaI Offline
        ibiaI Offline
        ibia
        wrote on last edited by
        #6

        Can you show a screenshot of the slider ?

        Naveen_DN 1 Reply Last reply
        2
        • ibiaI ibia

          Can you show a screenshot of the slider ?

          Naveen_DN Offline
          Naveen_DN Offline
          Naveen_D
          wrote on last edited by
          #7

          @ibia i am not able to upload the screen shot.

          Naveen_D

          Pradeep KumarP 1 Reply Last reply
          0
          • ibiaI Offline
            ibiaI Offline
            ibia
            wrote on last edited by
            #8

            Sorry! But, you will probably be more difficult to help if we do not have a screenshot of the problem.

            1 Reply Last reply
            1
            • Naveen_DN Naveen_D

              @ibia i am not able to upload the screen shot.

              Pradeep KumarP Offline
              Pradeep KumarP Offline
              Pradeep Kumar
              wrote on last edited by Pradeep Kumar
              #9

              @Naveen_D said in Regarding Slider in QML:

              @ibia i am not able to upload the screen shot.

              what is the reason y u cant upload?. it might help the users to provide looking into it.

              Thanks,

              Pradeep Kumar
              Qt,QML Developer

              1 Reply Last reply
              0
              • Naveen_DN Offline
                Naveen_DN Offline
                Naveen_D
                wrote on last edited by
                #10

                Hi, the issue is resolved( i am not sure), in the code i was assigning the minimum value as the slider value. Instead of giving minimum value as slider value, i changed the slider value separately, it is working fine. the slider handle is updating to the particular value.
                Thanks

                Naveen_D

                1 Reply Last reply
                1
                • Pradeep KumarP Offline
                  Pradeep KumarP Offline
                  Pradeep Kumar
                  wrote on last edited by
                  #11

                  Hi,

                  @Naveen_D ,

                  Good to hear u got the issue resolved, can u please mark the topic as solved, and if u can provide the code snippet, which is working it wiil be helpful for the users in Forum,

                  Thanks,

                  Pradeep Kumar
                  Qt,QML Developer

                  Naveen_DN 1 Reply Last reply
                  0
                  • Pradeep KumarP Pradeep Kumar

                    Hi,

                    @Naveen_D ,

                    Good to hear u got the issue resolved, can u please mark the topic as solved, and if u can provide the code snippet, which is working it wiil be helpful for the users in Forum,

                    Thanks,

                    Naveen_DN Offline
                    Naveen_DN Offline
                    Naveen_D
                    wrote on last edited by
                    #12

                    ya sure @Pradeep-Kumar
                    i just changed the slider value to 50 instead of assigning minimum value.
                    working code :

                        Slider{
                            id:theslider
                            anchors.centerIn: parent
                            maximumValue: 100
                            value: 50
                            width: 250
                            style: SliderStyle {
                                groove: Rectangle{
                                    id: grooveMainrect
                                    height: 5
                                    antialiasing: true
                                    radius: 5
                                    color: "#847878"
                                    Rectangle {
                                        id: groovechildrect
                                        width: (parent.width * theslider.value)/theslider.maximumValue
                                        height: parent.height
                                        color: Qt.lighter("#7ea6d6", 1.2)
                                        radius: parent.radius
                                    }
                                }
                                handle: Rectangle{
                                    id:handlemainrect
                                    height: (handlechildrect.height/3)+2
                                    width: (handlechildrect.width/3)+2
                                    radius: handlechildrect.width/2
                                    anchors.verticalCenter: parent.verticalCenter
                                    color: Qt.lighter("#7ea6d6", 1.2)
                                    Rectangle {
                                        id: handlechildrect
                                        width: 25
                                        height: 25
                                        anchors.centerIn: parent
                                        color: "#ffffff"
                                        radius: width/2
                                        opacity: 0.5
                                    }
                                }
                            }
                        }
                    

                    Naveen_D

                    1 Reply Last reply
                    1
                    • M Offline
                      M Offline
                      Meistermosher
                      wrote on last edited by
                      #13

                      Hey dear devs,
                      I've got a similar problem.
                      I'm following this tutorial: https://www.youtube.com/watch?v=aMEQji7Rwrg
                      but, when it comes to the slider-part I'm pretty lost.

                      My slider doesn't move when I try to customize the handle (otherwise it works fine).
                      What am I missing here?

                      import QtQuick 2.0
                      import QtQuick.Controls 2.15
                      
                      
                      Slider {
                          id: temperatureControlSlider
                          value: 25
                          from: 16
                          to: 35
                          stepSize: 1
                      
                          orientation: Qt.Vertical
                      
                          background: Rectangle{
                              height: parent.height
                              width: 3
                              anchors.centerIn: parent
                          }
                          handle: Rectangle {
                      
                              y: temperatureControlSlider.topPadding + temperatureControlSlider.visualPosition * (temperatureControlSlider.availableHeight - height)
                              x: temperatureControlSlider.leftPadding + temperatureControlSlider.availableWidth / 2 - width / 2
                              border.color: temperatureControlSlider.pressed ? "green" : "white"
                              color: "black"
                              border.width: 3
                              width: 76
                              height: 76
                              radius: width / 2
                          }
                      }
                      

                      Any ideas? :(

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Meistermosher
                        wrote on last edited by
                        #14

                        Ok I helped myself right now by creating a Rectangle and setting the anchor to the handle.
                        Then I rendered everything necessary on top.

                            Rectangle{
                                anchors.centerIn: handle
                                z: 1
                                width: 76
                                height: 76
                                radius: width / 2
                                border.width: 3
                                border.color: temperatureControlSlider.pressed ? "green" : "white"
                                color: "black"
                        
                            }
                            Text{
                                anchors.centerIn: handle
                                z: 1
                                color: "red"
                                font.pixelSize: 30
                                text: temperatureControlSlider.value
                            }
                        }
                        

                        It's a bit strange because I found only solutions similar to my previous post. But maybe it's because of Qt6 or so.
                        You need to grab the handle (which is now "invisible") but yeah. It works x)

                        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
                        • Unsolved