Slider movement



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


  • Moderators

    @Sushma_MP Set the value ?



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


  • Qt Champions 2016

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


  • Moderators

    @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



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


  • Moderators

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.