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. is it possible to turn off stylesheet distribution?
Forum Updated to NodeBB v4.3 + New Features

is it possible to turn off stylesheet distribution?

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 1.5k 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.
  • D Offline
    D Offline
    django.Reinhard
    wrote on last edited by
    #7

    Hi,

    my html-knowledge is quite outdated, but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).

    Maybe that changed - don't know.

    ... any way: I won't change Qt. This project is a challenge for me, so I just use it and I have to live with the quirks and issues.

    I am spoiled by java, which has solved many things much more elegantly than Qt. I can't remember, that I ever had such shocking impressions than with using Qt, where I already had some.

    C JKSHJ 2 Replies Last reply
    0
    • D django.Reinhard

      Hi,

      my html-knowledge is quite outdated, but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).

      Maybe that changed - don't know.

      ... any way: I won't change Qt. This project is a challenge for me, so I just use it and I have to live with the quirks and issues.

      I am spoiled by java, which has solved many things much more elegantly than Qt. I can't remember, that I ever had such shocking impressions than with using Qt, where I already had some.

      C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #8

      @django-Reinhard said in is it possible to turn off stylesheet distribution?:

      but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).
      Maybe that changed - don't know.

      Your desktop application is not a web page. This is Qt Style Sheets, or QSS. It has some similarities to CSS but it is not CSS.

      Yo, I got that by now. The point is that no widget has an objectName by default.

      If you are using Qt Designer standalone or embedded in Qt Creator then every widget object gets an object name by default. It matches the name you see in the form object tree (and you can change those). Here is the code generated by uic for a simple combo box I dropped in the form.

              comboBox = new QComboBox(Form);
              comboBox->setObjectName(QString::fromUtf8("comboBox"));
      

      If you are hand coding the forms then you can set a object name if you want, or need, to so that QSS has a target you can use.

      1 Reply Last reply
      0
      • D django.Reinhard

        Hi,

        my html-knowledge is quite outdated, but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).

        Maybe that changed - don't know.

        ... any way: I won't change Qt. This project is a challenge for me, so I just use it and I have to live with the quirks and issues.

        I am spoiled by java, which has solved many things much more elegantly than Qt. I can't remember, that I ever had such shocking impressions than with using Qt, where I already had some.

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #9

        @django-Reinhard said in is it possible to turn off stylesheet distribution?:

        my html-knowledge is quite outdated, but if I remember well, a toplevel stylesheet did not overwrite a style-property used at a div, or whatever element (of cause without selectors).
        Maybe that changed - don't know.

        Sure it does.

        <html>
        <body>
        	<div style="color:red;">
        		I'm red.
        		<div>I'm red too, 'cos my parent is red.</div>
        		<div style="color:blue;">I'm blue, 'cos I don't want to be like my parent.</div>
        	</div>
        </body>
        </html>
        

        Widgets are analogous to the "div"s here.

        I just use it and I have to live with the quirks and issues.

        I am spoiled by java, which has solved many things much more elegantly than Qt. I can't remember, that I ever had such shocking impressions than with using Qt, where I already had some.

        Although @ChrisW67 is right that QSS is not CSS, Qt's style inheritance rules are fully consistent with CSS here. And CSS is used for websites all around the world, so it really shouldn't be so shocking.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        3
        • D Offline
          D Offline
          django.Reinhard
          wrote on last edited by
          #10

          @JKSH said in is it possible to turn off stylesheet distribution?:

          Widgets are analogous to the "div"s here.

          Well, from what I tested, they are not.

          Your sample with the divs is what I believed in.
          But Qt behave different.

          First I set background color to FixtureManager, which is the notebook-page. Messagebox, child-editors and QLineEdits are all children of FixtureManager - so all changed to green.

          Then I set background-color of QLineEdit to white, but they stayed green. I tried to change autofillBackground, but it made no difference.
          Then I tried the same for the child editor. But setting backgroundcolor was not taken into account. All stayed green.
          That was the reason why I was shocked!

          The div sample is ok and if Qt would behave the same, everything would be fine.

          JonBJ JKSHJ 2 Replies Last reply
          0
          • D django.Reinhard

            @JKSH said in is it possible to turn off stylesheet distribution?:

            Widgets are analogous to the "div"s here.

            Well, from what I tested, they are not.

            Your sample with the divs is what I believed in.
            But Qt behave different.

            First I set background color to FixtureManager, which is the notebook-page. Messagebox, child-editors and QLineEdits are all children of FixtureManager - so all changed to green.

            Then I set background-color of QLineEdit to white, but they stayed green. I tried to change autofillBackground, but it made no difference.
            Then I tried the same for the child editor. But setting backgroundcolor was not taken into account. All stayed green.
            That was the reason why I was shocked!

            The div sample is ok and if Qt would behave the same, everything would be fine.

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

            @django-Reinhard
            Then maybe your code is wrong, we can't see it. More specific rules should override more generic rules in QSS, like in CSS.

            D 1 Reply Last reply
            0
            • D django.Reinhard

              @JKSH said in is it possible to turn off stylesheet distribution?:

              Widgets are analogous to the "div"s here.

              Well, from what I tested, they are not.

              Your sample with the divs is what I believed in.
              But Qt behave different.

              First I set background color to FixtureManager, which is the notebook-page. Messagebox, child-editors and QLineEdits are all children of FixtureManager - so all changed to green.

              Then I set background-color of QLineEdit to white, but they stayed green. I tried to change autofillBackground, but it made no difference.
              Then I tried the same for the child editor. But setting backgroundcolor was not taken into account. All stayed green.
              That was the reason why I was shocked!

              The div sample is ok and if Qt would behave the same, everything would be fine.

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by JKSH
              #12

              @django-Reinhard said in is it possible to turn off stylesheet distribution?:

              The div sample is ok and if Qt would behave the same, everything would be fine.

              Everything is fine then:

              auto topLevel = new QWidget;
              auto layout = new QVBoxLayout;
              auto greenChild = new QLineEdit("Green like parent", topLevel);
              auto whiteChild = new QLineEdit("White like a boss", topLevel);
              
              topLevel->setStyleSheet("background-color: green;");
              whiteChild->setStyleSheet("background-color: white;");
              
              layout->addWidget(greenChild);
              layout->addWidget(whiteChild);
              topLevel->setLayout(layout);
              topLevel->show();
              

              Tested on Qt 5.15.2, MinGW 64-bit.

              @Bonnie said in Weird stylesheet behavior for ui form designer:

              The styleSheet you set on a widget will also apply to all his children.

              What a stupid feature :(

              Bonnie was talking about how greenChild inherits the green background from its parent.

              As you can see, whiteChild can definitely be white, even if its parent is green.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • JonBJ JonB

                @django-Reinhard
                Then maybe your code is wrong, we can't see it. More specific rules should override more generic rules in QSS, like in CSS.

                D Offline
                D Offline
                django.Reinhard
                wrote on last edited by
                #13

                @JonB said in is it possible to turn off stylesheet distribution?:

                Then maybe your code is wrong

                Well, that may be true.

                I'm not that fit with Qt that I could state, that I don't make errors.
                I tested it with different widgets at different "distance" from parent and I got always the same result - every thing was green.

                So if it was my fault, I beg your pardon.

                JonBJ 1 Reply Last reply
                0
                • D django.Reinhard

                  @JonB said in is it possible to turn off stylesheet distribution?:

                  Then maybe your code is wrong

                  Well, that may be true.

                  I'm not that fit with Qt that I could state, that I don't make errors.
                  I tested it with different widgets at different "distance" from parent and I got always the same result - every thing was green.

                  So if it was my fault, I beg your pardon.

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

                  @django-Reinhard I just meant, we'd have to see the code just to be sure.

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    django.Reinhard
                    wrote on last edited by
                    #15

                    Hi,

                    never mind!

                    I'll learn the Qt-way of coding and it wasn't my last error ;)

                    JKSHJ 1 Reply Last reply
                    0
                    • D django.Reinhard

                      Hi,

                      never mind!

                      I'll learn the Qt-way of coding and it wasn't my last error ;)

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by
                      #16

                      @django-Reinhard said in is it possible to turn off stylesheet distribution?:

                      I'll learn the Qt-way of coding

                      Did you try the code in my last message?

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      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