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

QtQuick Controls 2 Style: Material.background and Universal.background NOT working



  • Hello everyone!
    I want to change background of Universal style, so buttons color would match the other stuff, but background property does not working :/ Other properties (accent, foreground and theme) work as it should. Also on the default style I can change colors of my buttons using palette.button: "#color", but I want to use Universal style on which palette.button: "#color" also does not working

    My code:

    main.qml:

    import QtQuick 2.13
    import QtQuick.Window 2.13
    import QtQuick.Controls.Universal 2.0
    import QtQuick.Controls 2.13
    
    Window {
        width: 640
        height: 480
        visible: true
        color: "#786969"
        title: qsTr("Hello World")
    
    
        Universal.accent: "Black"               //ok
        Universal.background: "Blue"            //NOT OK
        Universal.foreground: "Yellow"          //ok
        Universal.theme: Universal.Dark         //ok
    
        Button {
            id: button
            x: 270
            y: 138
            text: qsTr("Button")
        }
    
        CheckBox {
            id: checkBox
            x: 272
            y: 200
            text: qsTr("Check Box")
        }
    
        Slider {
            id: slider
            x: 220
            y: 264
            value: 0.5
        }
    
        Switch {
            id: switch1
            x: 267
            y: 334
            text: qsTr("Switch")
        }
    }
    

    main.py:

    import sys
    import os
    
    from PySide2.QtGui import QGuiApplication
    from PySide2.QtQml import QQmlApplicationEngine
    from PySide2.QtQuickControls2 import QQuickStyle
    
    
    if __name__ == "__main__":
        app = QGuiApplication(sys.argv)
        QQuickStyle.setStyle("Universal")
        engine = QQmlApplicationEngine()
        engine.load(os.path.join(os.path.dirname(__file__), "main.qml"))
    
        if not engine.rootObjects():
            sys.exit(-1)
        sys.exit(app.exec_())
    

    Thank you everyone for help! :D



  • I'm sending also printscreen:

    ed4435dc-2d4c-4d58-be1d-3763bb310f11-image.png


Log in to reply