Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Styling/theming QML in a CSS-like way
QtWS25 Last Chance

Styling/theming QML in a CSS-like way

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.0k Views
  • 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 Offline
    J Offline
    jesperhh
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved