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

QGuiApplication palette not set to ApplicationWindow



  • Re: QQuickView change controls palette

    It looks like the ApplicationWindow is not affected by the QGuiApplication's palette values.
    My environment is Qt 5.12.5 on Linux. I started over with an empty project to make sure of my results.

    main.cpp:

        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    
        QGuiApplication app(argc, argv);
    
        QPalette palette = QGuiApplication::palette();
        QPalette newPalette(palette);
        newPalette.setColor(QPalette::ColorRole::WindowText, QColor("#00FF00"));
        QGuiApplication::setPalette(newPalette);
    

    main.qml:

    ApplicationWindow {
        visible: true
        width: 640
        height: 480
    
        Component.onCompleted: {
            console.log("Text color : " + palette.windowText)
        }
    
        Text {
            text : "hello"
        }
    }
    

    Logs "Text color : #26282a"
    What am I missing if we refer to the documentation?



  • Hi @jean_b

    Probably You have to specify a color group which the change affects:

    newPalette.setColor(QPalette::Active, QPalette::WindowText, QColor("#00FF00"));
    

    It works for me.


Log in to reply