Styling/theming QML in a CSS-like way



  • Hi!

    I know that QML does not support CSS styling like widgets do, and I have read up on different alternative approaches to styling/theming:

    Common for these approaches is that they require the developer to specify the parts of the QML that can be styled, either by binding to a property in a “styling QML file/singleton”, or by using a Loader to load a different QML component based on style name. What I would like is something that works like the "id" selector in CSS instead of the "class" selector, so that the individual QML files do not have to know whether they will be styled later on or not.

    My current approach make all the QML files look similar to this (using approach in link 2):
    Main.qml
    @Rectangle {
    Id: background
    color: g_theme.background.color
    //g_theme is defined in root context and loaded dynamically
    }@

    What I would like to do is:
    Main.qml
    @Rectangle {
    Id: background
    color: “green” // default color
    }@

    And then have a styling file that defines (or similar)
    @Main.qml #background: red@

    Is this possible at the moment, or something that is in the pipeline for a future Qt version, or will the preferred way of styling continue to be something similar to the approach described in the links above?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Interesting question and proposition, however, I would recommend to post them on the interest mailing list. You'll find there Qt's developers/maintainers. This forum is more user oriented


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.