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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 8 Aug 2016, 22:01 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

    I 1 Reply Last reply 9 Aug 2016, 05:38
    2
    • S SGaist
      8 Aug 2016, 22:01

      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 ?

      I Offline
      I Offline
      IMAN4K
      wrote on 9 Aug 2016, 05:38 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
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 9 Aug 2016, 06:59 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

        I 1 Reply Last reply 9 Aug 2016, 07:53
        2
        • S SGaist
          9 Aug 2016, 06:59

          Then why not just set that external style sheet directly ?

          I Offline
          I Offline
          IMAN4K
          wrote on 9 Aug 2016, 07:53 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 */);

          K 1 Reply Last reply 9 Aug 2016, 09:36
          0
          • I IMAN4K
            9 Aug 2016, 07:53

            @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 */);

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 9 Aug 2016, 09:36 last edited by
            #6

            @IMAN4K

            Isn't the windowOpacity property holding that?

            Read and abide by the Qt Code of Conduct

            I 1 Reply Last reply 9 Aug 2016, 10:15
            0
            • K kshegunov
              9 Aug 2016, 09:36

              @IMAN4K

              Isn't the windowOpacity property holding that?

              I Offline
              I Offline
              IMAN4K
              wrote on 9 Aug 2016, 10:15 last edited by IMAN4K 8 Sept 2016, 10:15
              #7

              @kshegunov
              No. it return 1

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 9 Aug 2016, 20:55 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

                I 1 Reply Last reply 10 Aug 2016, 05:00
                1
                • S SGaist
                  9 Aug 2016, 20:55

                  Are you doing all the painting yourself ?

                  I Offline
                  I Offline
                  IMAN4K
                  wrote on 10 Aug 2016, 05:00 last edited by
                  #9

                  @SGaist
                  yes

                  D 1 Reply Last reply 12 Aug 2016, 02:15
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 11 Aug 2016, 21:30 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
                    • I IMAN4K
                      10 Aug 2016, 05:00

                      @SGaist
                      yes

                      D Offline
                      D Offline
                      Devopia53
                      wrote on 12 Aug 2016, 02:15 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;
                                  }
                              }
                          }
                      }
                      [...]
                      
                      I 1 Reply Last reply 12 Aug 2016, 10:40
                      2
                      • D Devopia53
                        12 Aug 2016, 02:15

                        @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;
                                    }
                                }
                            }
                        }
                        [...]
                        
                        I Offline
                        I Offline
                        IMAN4K
                        wrote on 12 Aug 2016, 10:40 last edited by IMAN4K 8 Dec 2016, 10:41
                        #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

                        11/12

                        12 Aug 2016, 02:15

                        • Login

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