Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Styling/theming QML in a CSS-like way

    QML and Qt Quick
    2
    2
    1742
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jesperhh last edited by

      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:

      • https://qt-project.org/wiki/QmlStyling
      • http://www.slideshare.net/BurkhardStubert/practical-qml-key-navigation/34

      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?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • First post
          Last post