Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Slider movement

    QML and Qt Quick
    3
    7
    1298
    Loading More Posts
    • 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.
    • S
      Sushma_MP last edited by Sushma_MP

      Hi,

      I have a slider functionality in Qt, i need to update the movement of slider in QML by reading the value from Qt functionality.

      1 Reply Last reply Reply Quote 0
      • p3c0
        p3c0 Moderators last edited by

        @Sushma_MP Set the value ?

        157

        1 Reply Last reply Reply Quote 1
        • S
          Sushma_MP last edited by

          yes i want to set the value to the slider developed in QML.
          how to do that...?

          mrjj p3c0 2 Replies Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion @Sushma_MP last edited by

            @Sushma_MP
            Hi you should show your code with the c++ signal
            and the QML where you want to get the slider signal.

            1 Reply Last reply Reply Quote 0
            • p3c0
              p3c0 Moderators @Sushma_MP last edited by

              @Sushma_MP said in Slider movement:

              yes i want to set the value to the slider developed in QML.
              how to do that...?

              assign a value to value using id

              157

              1 Reply Last reply Reply Quote 1
              • S
                Sushma_MP last edited by

                Hi,

                Below code is to set and update the position in cpp in which am emitting signal with slider position.

                //SelectedSong.cpp

                //setPosition method
                
                void SelectedSong::setPosition(int position)
                {
                    if (qAbs(mediaplayer->position() - position) > 99)
                    {
                        mediaplayer->setPosition(position);
                
                      emit signaltogetsliderposition(position);
                    }
                }
                
                //update position method
                void SelectedSong::updatePosition(qint64 position)
                {
                    positionSlider->setValue(position);
                    QTime duration(0, position / 60000, qRound((position % 60000) / 1000.0));
                }
                
                

                I catched that signal in QML as below:

                 Selectedsong{
                        id:mysong
                        onSignaltogetsliderposition:
                        {
                            console.log("signal catched...")
                        }
                    }
                

                Am creating slider in QML as fallows:

                // Creation of Slider in QML

                 Slider {
                                id: control
                                value: 0.0
                
                                background: Rectangle {
                                    x: control.leftPadding
                                    y: control.topPadding + control.availableHeight / 2 - height / 2
                                    implicitWidth: music_main_rect.width/2
                                    implicitHeight: music_main_rect.height/50
                                    width: control.availableWidth
                                    height: implicitHeight
                                    radius: 4
                                    //color: "#474647"
                                    color: "#bdbebf"
                
                
                                    Rectangle {
                                        width: control.visualPosition * parent.width
                                        height: parent.height
                                        //color: "#bdbebf"
                                        color: "#5da9e9"
                                        radius: 4
                                    }
                                }
                
                                handle: Rectangle {
                                    x: control.leftPadding + control.visualPosition * (control.availableWidth - width)
                                    y: control.topPadding + control.availableHeight / 2 - height / 2
                                    implicitWidth: 26
                                    implicitHeight: 26
                                    radius: 13
                                    color: control.pressed ? "#f0f0f0" : "#f6f6f6"
                                    border.color: "#bdbebf"
                                }
                            }
                

                Problem is i am not understanding how can i set that sliderposition from cpp file to this value present in slider.

                1 Reply Last reply Reply Quote 0
                • p3c0
                  p3c0 Moderators last edited by

                  @Sushma_MP Can't you access Slider using its id in onSignaltogetsliderposition ?

                  157

                  1 Reply Last reply Reply Quote 2
                  • First post
                    Last post