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. Style sheet woes
Qt 6.11 is out! See what's new in the release blog

Style sheet woes

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.2k Views 1 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.
  • G Offline
    G Offline
    GrahamL
    wrote on last edited by
    #1

    Hi
    I have a style sheet that sets the background colour for QDialog -
    @
    QDialog {
    background-color: red;
    }
    @
    My application has a QListWidget added from Designer and is created with its containing layout as the parent,
    Upon selecting an element in the list I launch a dialog, but the style sheet is not applied to this dialog.
    I believe that this is because the list widget is not created with my main window as a parent

    I thought that by specifying the background colour in the style sheet that all dialogs (regardless of parent) would have the same background colour.

    I would be grateful if someone could explain why this is not the case

    Thanks in advance

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Style information is propagated down the line: from parent to all children. If you create an unparented dialog, you need to set the stylesheet on it yourself.

      (Z(:^

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GrahamL
        wrote on last edited by
        #3

        Hi
        thanks for your quick response
        here is the code I use to create the dialog
        @
        UserInterface::SessionManagementUI::CreateSessionDialog dialog(this);
        @
        so I am creating it with a parent

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Do you set that stylesheet on your whole application, or on a certain widget? Maybe the setStyleSheet() call is on a different branch of parent-child tree?

          (Z(:^

          1 Reply Last reply
          0
          • G Offline
            G Offline
            GrahamL
            wrote on last edited by
            #5

            Hi
            I set the style sheet in the constructor of my main window -
            @
            QString style = "QDialog {background-color: red;}";
            qApp->setStyleSheet(style);
            @

            If I find the main window and use that as the parent then the dialog is displayed as expected -
            @
            QWidget*x = this->parentWidget();
            x = x->parentWidget();
            x = x->parentWidget();
            UserInterface::SessionManagementUI::CreateSessionDialog dialog(x);
            @

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Ok, this seems like a bug then. Qt4 or 5?

              (Z(:^

              1 Reply Last reply
              0
              • G Offline
                G Offline
                GrahamL
                wrote on last edited by
                #7

                I am using 5.0.2

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  Please test in Qt4 if possible, and "report it on Jira":https://qt-project.org/wiki/ReportingBugsInQt.

                  (Z(:^

                  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