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

very simply style of switch ...



  • for first I'm on qt5.11 quickcontrol2 ... style=Default ... I would like to change the background color without having to make a qml style file with transitions and everything else. Is it possible to keep the current style with all its transitions and change only the dark-gray in blue with a single line of code?

    regards



  • @gfxx hi
    edit my bad this was not for QtQuickControls 2
    see SwitchStyle
    ```
    Switch {
    style: SwitchStyle {
    groove: Rectangle {
    implicitWidth: 100
    implicitHeight: 20
    radius: 9
    color: "darkblue"
    border.width: 1
    }
    }
    }


  • Lifetime Qt Champion

    Hi,

    For the QtQuickControls 2, the reference is here.



  • i see these link .... but if use that system i loose transition effect .... so i must implement effect too ... not so easy. In these manner for change one only color in 3/4 widget i must write 300/400 row of code ... very slow system ... there are not some other system for change one only "active background color" whitout implement again all widget style? (like css manner)??



  • @gfxx said in very simply style of switch ...:

    .. 3/4 must write 300/400 100 row of code

    you can reuse components



  • these for sure .... but I need only one component with that colour !!!!

    not very scalable .... In these way for first I must rewrite every component style ... than if I need a specific change i need to copy and modify component style ..... so probabily I need 30/40 or more component filestyle.qml .... not so intelligent way to do the things. Ok probabily is not so important in a bigger company project .... but in smart project .... really there are not another way to do these?

    In that case better is to use c++ widget and css code.

    in these moment I have a little idea .... where is locate the quick2 controls? I think is better copy it and modify as custom style comp.


  • Qt Champions 2018

    There is multiple way to do this depending on which Qt Quick Controls 2 style you are using.

    Generally you can just modify your Control's palette : https://doc.qt.io/qt-5/qml-qtquick-controls2-control.html#palette-prop
    But some style (like the Material one) don't use palette but their own attached properties instead, for example : https://doc.qt.io/qt-5/qtquickcontrols2-material.html



  • @GrecKo ok .... but I'm on ui.qml file .... sems not consent. So I must export witch property?

    -- Update ---

    is these a good way to do these things:

    QObject *myButton= object->findChild<QObject*>("myButton");
    if (myButton)
        myButton->setProperty("color", "red");
    

    There are some setPalette property for switch?

    regards


Log in to reply