1

I'm playing around with Qt 5.8 RC and the new attribute System introduced in both Universal and Material themes.

However when designing a customizable app, one can choose Universal or Material in combination with Dark, Light or System. How can I know that System is actually not the string "System" but either "Dark" or "Light"?

Here's what I'm trying to build (settings.qml): Miam-Player-QML

RadioButton {
    text: qsTr("Light")
    checked: appSettings.theme === "Light"
    ButtonGroup.group: modeBG
    onClicked: {
        appSettings.theme = "Light"
        appSettings.background = "white"
        appSettings.menuPaneColor = "#eeeeee"
    }
}
RadioButton {
    text: qsTr("Dark")
    checked: appSettings.theme === "Dark"
    ButtonGroup.group: modeBG
    onClicked: {
        appSettings.theme = "Dark"
        appSettings.background = "black"
        appSettings.menuPaneColor = "#171717"
    }
}
RadioButton {
    text: qsTr("System theme")
    ButtonGroup.group: modeBG
    onClicked: {
        appSettings.theme = "System"
        //appSettings.background = "black"
        //appSettings.menuPaneColor = "#171717"
    }
}

Obviously, the following code which used to work with "hard" values no longer works (main.qml):

ToolButton {
    id: burgerMenu
    checkable: appSettings.burgerMenuIsChecked
    contentItem: Image {
        fillMode: Image.Pad
        horizontalAlignment: Image.AlignHCenter
        verticalAlignment: Image.AlignVCenter
        source: "qrc:/images/" + appSettings.style + "/" + appSettings.theme + "/drawer.png"
    }
    ...
}

Any idea?

demonplus
  • 5,613
  • 12
  • 49
  • 68
MBach
  • 1,647
  • 16
  • 30
  • You could specify different [configuration files](https://doc-snapshots.qt.io/qt5-5.8/qtquickcontrols2-configuration.html) and try to do that check in C++ – DuKes0mE Jan 09 '17 at 10:41

1 Answers1

2

The documentation says:

Setting the theme to System chooses either the light or dark theme based on the system theme colors. However, when reading the value of the theme property, the value is never System, but the actual theme.

So, if you check the values of Material.theme and Universal.theme, both should return their effective values, rather than the value that you set.

Mitch
  • 23,716
  • 9
  • 83
  • 122
  • Hmm.. That's strange because onClicked: { console.log(Material.theme) } always returns qml: 0 in Qt Creator – MBach Jan 07 '17 at 23:27
  • `Material.theme: Material.Dark; Component.onCompleted: print(Material.theme)` prints `1` for me. Setting `Material.theme: Material.System` will use whatever your system is using, so if that's a light theme, it's always going to return `0`: http://code.qt.io/cgit/qt/qtquickcontrols2.git/tree/src/imports/controls/material/qquickmaterialstyle_p.h#n104 – Mitch Jan 08 '17 at 09:06
  • 1
    I think the RC that I have downloaded isn't working well. When I start a new project from scratch using Assistant (and putting latest release number in imports), `Accent=BlueGrey` in `qtquickcontrols2.conf` doesn't work: I see an error in console, `Theme=Dark` or `Theme=Light` is fine, but `Theme=System` always fallback on light. – MBach Jan 08 '17 at 14:40
  • I can't do much without having a complete example to try out, sorry. – Mitch Jan 08 '17 at 18:09
  • You can check with Gallery example : http://doc.qt.io/qt-5/qtquickcontrols2-gallery-example.html, it has a `qtquickcontrols2.conf` file. – MBach Jan 10 '17 at 17:31
  • With regards to the original question though, `Theme=System` always resulting in the light theme makes perfect sense if your system is using a light theme. I don't see the issue there. – Mitch Jan 10 '17 at 18:58
  • 1
    Indeed, but on Windows now you can set Dark or Light, and this is reflected in app like Calculator, but never in Qt Apps. So I've opened an issue here : https://bugreports.qt.io/browse/QTBUG-58055 which is basically this thread. – MBach Jan 10 '17 at 19:00