Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Simple way to change QML slider background color?



  • import QtQuick.Controls 2.4

    is the version I am using.

    The default gray blends too much with my background color of the page and I would like to change the undragged portion to black and the dragged portion to some other color like green.

    Is there is a simple approach to setting the background colors?

    I found this but it seems a little overcomplicated, or at the very least I am having trouble working out the positioning.

    Here is the relevant snippet from that link:

    background: Rectangle {
            y: (control.height - height) / 2
            height: 4
            radius: 2
            color: UIStyle.colorQtGray3
    
            Rectangle {
                width: control.visualPosition * parent.width
                height: parent.height
                color: UIStyle.colorQtAuxGreen2
                radius: 2
            }
        }
    

    When I start to implement this code I am unable to properly position my slider.


  • Moderators

    @MrShawn said in Simple way to change QML slider background color?:

    When I start to implement this code I am unable to properly position my slider.

    see this



  • Yeap, I see it setting x and y there, along with implicit sizes, thank you much sir.


Log in to reply