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

Why the app theme did not change with the system



  • I have specified the Material theme as "System" in qtquickcontrols2.conf, and the current macOS theme is set to dark mode. But when I compile and re-run the application, the title bar and window contents of the application are still displayed in light mode.

    [Controls]
    Style=Material
    
    [Material]
    Primary=#41cd52
    Accent=#41cd52
    Theme=System
    

    What other settings should I make?



  • @Dylan-Deng

    Don't know how you could do it in qtquickcontrols2.conf, but you could do this, as described by the docs,
    Maybe specifying Universal.System in conf works too..

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    import QtQuick.Controls.Universal 2.12
    
    ApplicationWindow {
        visible: true
        Universal.theme: Universal.System
        
        Column {
            anchors.centerIn: parent
            RadioButton { text: qsTr("Small") }
            RadioButton { text: qsTr("Medium");  checked: true }
            RadioButton { text: qsTr("Large") }
        }
    }
    

    https://doc.qt.io/qt-5/qtquickcontrols2-universal.html



  • @Dylan-Deng seems like you should be able to do this;

    [Controls]
    Style=Universal

    [Universal]
    Theme=System



  • There is plenty of information on this subject, found with a simple search. for example;

    https://doc.qt.io/qt-5/qtquickcontrols2-configuration.html ~ this page gives some pretty detailed configurations for various themes/fonts/colours.



  • @Markkyboy I spent an afternoon through google and Qt documents, which failed to achieve the program to change the theme color according to the theme set by the system.

    According to the documentation, the only thing I can see is that set Theme as System, but it does not work.

    The use of Universal.theme: Universal.System in QML files, it does not work too.



  • @Dylan-Deng You have also included the universtal style when testing Universal.theme:Universal.System ?

    import QtQuick.Controls.Universal 2.12
    

    And removed every other setting related to styles?



  • @MEMekaniske Yes, I'm using Qt example gallery and removed QQuickStyle::setStyle in mian.cpp

    QSettings settings;
    QString style = QQuickStyle::name();
    if (!style.isEmpty())
        settings.setValue("style", style);
    else
        QQuickStyle::setStyle(settings.value("style").toString());
    

    Then I set the qtquickcontrols2.conf like this:

    [Controls]
    Style=Material
    
    [Material]
    Primary=#41cd52
    Accent=#41cd52
    Theme=System
    

    It does not working out whether or not I set Material.theme: Material.System


Log in to reply