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. How to stop child dialogs from inheriting parent's StyleSheet
Forum Updated to NodeBB v4.3 + New Features

How to stop child dialogs from inheriting parent's StyleSheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 2 Posters 20.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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    Hi
    Stylesheets are cascading by nature. Any children will get the stylesheet.
    So if you set it up on application ALL will have same look.

    If you wish to have some dialogs not having the look, make your stylesheet better using the specifier #

    http://doc.qt.io/qt-5/stylesheet-examples.html

    so if you use
    QDialog {xxxx}
    You can target add name
    QDialog#Name {xxxx}
    and only those with that name are affected.

    So the solution is to fix the style sheet so it ONLY targets the Dialogs you want.

    There is no option to not make it cascading.

    1 Reply Last reply
    2
    • S Offline
      S Offline
      Sofia
      wrote on last edited by
      #3

      Thank you for the answer. But I don't undestandt yet how to use this syntax.
      I have the following text in "styleSheet" field for my dialog object in QtDesigner:

      QToolButton{background-color: transparent; border-radius: 3; border: 1 solid transparent;}
      QToolButton:disabled{color:#b0b0b0;}
      QScrollBar {border: none;background: transparent;}

      I tried
      QDialog#MyDialog
      {
      QToolButton{background-color: transparent; border-radius: 3; border: 1 solid transparent;}
      QToolButton:disabled{color:#b0b0b0;}
      QScrollBar {border: none;background: transparent;}
      }
      but it doesn't work.

      mrjjM 1 Reply Last reply
      0
      • S Sofia

        Thank you for the answer. But I don't undestandt yet how to use this syntax.
        I have the following text in "styleSheet" field for my dialog object in QtDesigner:

        QToolButton{background-color: transparent; border-radius: 3; border: 1 solid transparent;}
        QToolButton:disabled{color:#b0b0b0;}
        QScrollBar {border: none;background: transparent;}

        I tried
        QDialog#MyDialog
        {
        QToolButton{background-color: transparent; border-radius: 3; border: 1 solid transparent;}
        QToolButton:disabled{color:#b0b0b0;}
        QScrollBar {border: none;background: transparent;}
        }
        but it doesn't work.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @Sofia
        Its not the correct syntax/concept. :)
        If you have another dialog where QToolButton should not be style, you need to
        add names to that.
        What you have shown is not valid. (sadly)

        QToolButton#name {background-color: transparent; border-radius: 3; border: 1 solid transparent;}

        would be that.

        So that is the issue ?
        You have a "child" dialog of a dialog and ther you do not want
        QToolButton styling to take effect?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sofia
          wrote on last edited by Sofia
          #5

          It's the issue, yes! It's a main subject of my complain :(

          I have not only one QScrollBar and one QToolButton in my dialogs and their styleSheets.
          There are, for example, QLabel and QEdit styling - font, padding, color for particular dialog and many labels and edits in it. And I don't want this styling in auxiliary dialogs. Should I enumerate all them with '#'?

          I have a lot of different working dialogs with different styles, but I want to have constant Message dialog everywhere.
          I even can't have preview. I see one view in QtDesigner form and I see the absolutely different one in my program when this dialog is invoked from some parent window.

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #6

            Also
            Why cant u just use names for dialog ?
            So you list the names of the dialogs that should affect ?

            alt text

            the text label in the middle is called nope

            1 Reply Last reply
            2
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #7

              Alternatively, you can also create a common base class for the non styled
              dialogs. StyleSheet allows for type/class specifier also.
              So you could say only direct QDialogs.

              That way you can avoid specify names.

              http://doc.qt.io/qt-5/stylesheet-syntax.html

              S 1 Reply Last reply
              0
              • mrjjM mrjj

                Alternatively, you can also create a common base class for the non styled
                dialogs. StyleSheet allows for type/class specifier also.
                So you could say only direct QDialogs.

                That way you can avoid specify names.

                http://doc.qt.io/qt-5/stylesheet-syntax.html

                S Offline
                S Offline
                Sofia
                wrote on last edited by
                #8

                Thank you very much for your answers.
                I read stylesheet-syntax.html doc several times before I wrote to this forum and several times after.
                Could you please give an example for your last advice? What should I write for my child "Message" dialogs which now can have empty or non-empty styleSheets?

                mrjjM 1 Reply Last reply
                0
                • S Sofia

                  Thank you very much for your answers.
                  I read stylesheet-syntax.html doc several times before I wrote to this forum and several times after.
                  Could you please give an example for your last advice? What should I write for my child "Message" dialogs which now can have empty or non-empty styleSheets?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @Sofia

                  Hi
                  I was thinking of this section
                  alt text

                  S 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @Sofia

                    Hi
                    I was thinking of this section
                    alt text

                    S Offline
                    S Offline
                    Sofia
                    wrote on last edited by
                    #10

                    Thank you for details.
                    Actually parent dialog (not parent class, but parent widget from which child dialog is invoked) can have QLabels and QLabel-based modified widgets and child dialog also can have "pure" and modified QLabels.

                    In any case the "summary" is - I always have to think specially and very thoroughly if some dialog can launch any child dialogs and if this dialog can be launched with parent.

                    All the same I see some logical error here...

                    mrjjM 1 Reply Last reply
                    0
                    • S Sofia

                      Thank you for details.
                      Actually parent dialog (not parent class, but parent widget from which child dialog is invoked) can have QLabels and QLabel-based modified widgets and child dialog also can have "pure" and modified QLabels.

                      In any case the "summary" is - I always have to think specially and very thoroughly if some dialog can launch any child dialogs and if this dialog can be launched with parent.

                      All the same I see some logical error here...

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @Sofia
                      Hi
                      You mean, its not full dialog you want to keep un-styled ?
                      But elements within?

                      There is also

                      class MyPushButton : public QPushButton {
                          // ...
                      }
                      
                      // ...
                      qApp->setStyleSheet("MyPushButton { background: yellow; }");
                      

                      Where you use the subclass type.
                      Note, u can use , for a list
                      MyPushButton, X, Y

                      But if you mean styled and un-styled is mixed , that wont help.

                      There is also option to use dynamic proprieties to flag stuff.
                      https://wiki.qt.io/Dynamic_Properties_and_Stylesheets

                      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