Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Reading CSS property from C++ code
Forum Updated to NodeBB v4.3 + New Features

Reading CSS property from C++ code

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.2k Views 2 Watching
  • 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.
  • P Offline
    P Offline
    peter-70
    wrote on last edited by peter-70
    #1

    As the title suggests, I would like to know if it is possible to read CSS properties or attributes from my C ++ code.Thanks for your tips!

    For (abstract) example:

    QVariant getValue(QWidget* widget, const QString& propertyName)
    {
        return widget->style()->getValue(propertyName);
    }
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      You would have to parse the stylesheet yourself.
      There is no API for it. sadly.
      You could look at Qt source for its cssparser or
      be inspired from
      https://www.codeproject.com/Articles/20450/Simple-CSS-Parser

      1 Reply Last reply
      4
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        There's plenty of libraries available that can parse CSS, for example: https://github.com/lexborisov/mycss

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        2
        • P Offline
          P Offline
          peter-70
          wrote on last edited by
          #4

          Ok, but there is not any Qt's own functionality to do that? I know, I can parse the styleSheet, but when Qt were able to giving me what I'm searching for, it could be surly the better way to solve this problem (...I think)

          JonBJ 1 Reply Last reply
          0
          • P peter-70

            Ok, but there is not any Qt's own functionality to do that? I know, I can parse the styleSheet, but when Qt were able to giving me what I'm searching for, it could be surly the better way to solve this problem (...I think)

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @peter-70
            That's why the answers are saying that there is not such an inbuilt Qt API for this....

            VRoninV 1 Reply Last reply
            0
            • JonBJ JonB

              @peter-70
              That's why the answers are saying that there is not such an inbuilt Qt API for this....

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @JonB said in Reading CSS property from C++ code:

              there is not such an inbuilt Qt API for this

              Irrelevant note: there is (it's the one Qt uses to read style sheets applied to widgets) but it's not exposed to the external users, it's private to the libraries

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              JonBJ 1 Reply Last reply
              2
              • VRoninV VRonin

                @JonB said in Reading CSS property from C++ code:

                there is not such an inbuilt Qt API for this

                Irrelevant note: there is (it's the one Qt uses to read style sheets applied to widgets) but it's not exposed to the external users, it's private to the libraries

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #7

                @VRonin
                Yes, that's what I meant, as per @mrjj's

                You could look at Qt source for its cssparser

                On this note, are you a person to consider whether Qt might like to expose this at a future date? Qt offers offers so much miscellaneous useful stuff, it might be a nice addition....

                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