c++qt

Is it possible to customize slider in qt?


Is it possible to make a slider with an image? not as a background but like an image i pull up and down instead of the slider?

I have searched around and saw some examples of redrawing a slider, is it something like this i need to do, if so any examples you can link me too?

Also saw something called QML slider, can my project be achieved with that, if so any examples would be great!

I should mention im new to Qt and programming in general, so sorry in advance for any stupid mistakes i migth make .


Solution

  • With the Slider from Qt Quick Controls:

    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtQuick.Controls.Styles 1.1
    
    Item {
        width: 400
        height: 400
        Slider {
            anchors.centerIn: parent
            style: SliderStyle {
                handle: Image {
                    source: "http://icons.iconarchive.com/icons/custom-icon-design/pretty-office-9/256/square-icon.png"
                    width: 14
                    height: 14
                }
            }
        }
    }
    

    custom-slider-handle

    See SliderStyle's documentation for more information.