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. Using Qt private CSS parser
Forum Updated to NodeBB v4.3 + New Features

Using Qt private CSS parser

Scheduled Pinned Locked Moved Solved General and Desktop
cssparserqcssparserqt5
12 Posts 4 Posters 3.1k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    You would have to enable the use of the private parts of Qt with all the big fat warnings that comes with it.

    Why do you want to parse your css since you already know what's in it ?

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

    IMAN4KI 1 Reply Last reply
    2
    • SGaistS SGaist

      Hi,

      You would have to enable the use of the private parts of Qt with all the big fat warnings that comes with it.

      Why do you want to parse your css since you already know what's in it ?

      IMAN4KI Offline
      IMAN4KI Offline
      IMAN4K
      wrote on last edited by
      #3

      @SGaist

      You would have to enable the use of the private parts of Qt with all the big fat warnings that comes with it.

      I already compile it (and also disable warnings) :

      int main() {
          QString css = "RadioButton {"
                          "color:#009688;"
                          "font-size:12pt;"
                          "opacity:0.5;"
                          "}";
          QCss::Parser parser(css);
      }
      

      But at this time i want to get the color value (#009688) of RadioButton but the source code of this parser is complicated (may be i should make the parse tree)

      Why do you want to parse your css since you already know what's in it ?

      Because i want to read an external CSS file and get my app's widgets properties from it.
      For example : in my RadioButton painting i use an opacity value and when i change the opacity from CSS file all RadioButton must be change to new opacity.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Then why not just set that external style sheet directly ?

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

        IMAN4KI 1 Reply Last reply
        2
        • SGaistS SGaist

          Then why not just set that external style sheet directly ?

          IMAN4KI Offline
          IMAN4KI Offline
          IMAN4K
          wrote on last edited by
          #5

          @SGaist
          Well.
          We assigned stylesheet :

          class RadioButton : public QAbstractButton
          {
          public:
          	RadioButton() {
          		QString css = "RadioButton {"
          							"color:#009688;"
          							"font-size:12pt;"
          							"opacity:0.5;"
          							"}";
          		setStyleSheet(css);
          	}
          };
          

          But the problem is accessing the values So how we should get opacity :
          QPainter::setOpacity(/* required opacity */);

          kshegunovK 1 Reply Last reply
          0
          • IMAN4KI IMAN4K

            @SGaist
            Well.
            We assigned stylesheet :

            class RadioButton : public QAbstractButton
            {
            public:
            	RadioButton() {
            		QString css = "RadioButton {"
            							"color:#009688;"
            							"font-size:12pt;"
            							"opacity:0.5;"
            							"}";
            		setStyleSheet(css);
            	}
            };
            

            But the problem is accessing the values So how we should get opacity :
            QPainter::setOpacity(/* required opacity */);

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #6

            @IMAN4K

            Isn't the windowOpacity property holding that?

            Read and abide by the Qt Code of Conduct

            IMAN4KI 1 Reply Last reply
            0
            • kshegunovK kshegunov

              @IMAN4K

              Isn't the windowOpacity property holding that?

              IMAN4KI Offline
              IMAN4KI Offline
              IMAN4K
              wrote on last edited by IMAN4K
              #7

              @kshegunov
              No. it return 1

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Are you doing all the painting yourself ?

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

                IMAN4KI 1 Reply Last reply
                1
                • SGaistS SGaist

                  Are you doing all the painting yourself ?

                  IMAN4KI Offline
                  IMAN4KI Offline
                  IMAN4K
                  wrote on last edited by
                  #9

                  @SGaist
                  yes

                  D 1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    What attributes are you going to support ?

                    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
                    1
                    • IMAN4KI IMAN4K

                      @SGaist
                      yes

                      D Offline
                      D Offline
                      Devopia53
                      wrote on last edited by
                      #11

                      @IMAN4K said:

                      Now i'm going to retrieve RadioButton's properties from Style.css
                      for that after some searching i found Qt private CSS scanner and parser :
                      qcssscanner.cpp
                      qcssparser_p.h
                      qcssparser.cpp

                      And now i don't know how to use this parser to get token types + values

                      Hi.

                      Something like this... Not recommended...

                      #include <QtGui/5.7.0/QtGui/private/qcssparser_p.h>
                      
                      [...]
                      QCss::Parser parser(yourStyleSheetString);
                      
                      while (parser.testSelector()) {
                          QCss::StyleRule styleRule;
                      
                          if (parser.parseRuleset(&styleRule)) {
                              foreach (auto sel, styleRule.selectors) {
                                  foreach (auto bSel, sel.basicSelectors) {
                                      qDebug() << "BasicSelector:" << bSel.elementName;
                                  }
                              }
                      
                              foreach (auto decl, styleRule.declarations) {
                                  qDebug() << "property:" << decl.d->property;
                                  foreach (auto value, decl.d->values) {
                                     qDebug() << "value:" << value.variant;
                                  }
                              }
                          }
                      }
                      [...]
                      
                      IMAN4KI 1 Reply Last reply
                      2
                      • D Devopia53

                        @IMAN4K said:

                        Now i'm going to retrieve RadioButton's properties from Style.css
                        for that after some searching i found Qt private CSS scanner and parser :
                        qcssscanner.cpp
                        qcssparser_p.h
                        qcssparser.cpp

                        And now i don't know how to use this parser to get token types + values

                        Hi.

                        Something like this... Not recommended...

                        #include <QtGui/5.7.0/QtGui/private/qcssparser_p.h>
                        
                        [...]
                        QCss::Parser parser(yourStyleSheetString);
                        
                        while (parser.testSelector()) {
                            QCss::StyleRule styleRule;
                        
                            if (parser.parseRuleset(&styleRule)) {
                                foreach (auto sel, styleRule.selectors) {
                                    foreach (auto bSel, sel.basicSelectors) {
                                        qDebug() << "BasicSelector:" << bSel.elementName;
                                    }
                                }
                        
                                foreach (auto decl, styleRule.declarations) {
                                    qDebug() << "property:" << decl.d->property;
                                    foreach (auto value, decl.d->values) {
                                       qDebug() << "value:" << value.variant;
                                    }
                                }
                            }
                        }
                        [...]
                        
                        IMAN4KI Offline
                        IMAN4KI Offline
                        IMAN4K
                        wrote on last edited by IMAN4K
                        #12

                        @Devopia53
                        Excellent answer :)

                        Not recommended...

                        Yeah know it and i make these files local in my project (not include from <private/qcssparser_p.h>):
                        qcssscanner.cpp
                        qcssparser_p.h
                        qcssparser.cpp

                        Thank you

                        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