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 share a single style sheet across multiple .ui Qt Designer files

How to share a single style sheet across multiple .ui Qt Designer files

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 9.4k Views
  • 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
    DanBrakeley
    wrote on last edited by
    #1

    I'm a new developer, and maybe I'm going about this wrong, but I've got an application that is made up of a main window and multiple dock widgets and additional custom dialogs. Each of these windows (or is the right word here widgets?) has their own .ui file. I was hoping to set up a single style sheet that could be shared across all of them.

    I can get it to work at runtime by putting all my styles in a single text (.qss) file, and loading that into a string, and then setting it on the QApplication object via setStyleSheet(). The problem with this solution is that those styles are not applied to what is seen in Qt Designer. Is there a way to share a single style sheet across multiple .ui files in Qt Designer?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      Yes, and QApplication::setStyleSheet is a good way to do it. I think you just need to be a bit more specific about what you're doing and what's not working.

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DanBrakeley
        wrote on last edited by
        #3

        So all my styles are in file.qss, which is loaded at runtime by my app, and then I call mApp->setStyleSheet(stringLoadedQssFile);. Qt Designer, meanwhile, doesn't know about file.qss, nor does it load it up. Can I make Qt Designer load up this qss file and use its contents as the master style sheet for any given .ui file?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tmcb
          wrote on last edited by
          #4

          I am wondering the same thing. I find myself replicating the same style sheet settings across multiple forms which has been proven to be very difficult maintaining consistent styling across all my forms. Is there any way Designer can apply the stylesheets in the projects resource folder to the ui forms?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DanBrakeley
            wrote on last edited by
            #5

            So we never did solve this problem. Our UI artist just runs the actual app to preview his changes. This sucks when there are .ui or code changes that need to recompile, and the app itself has a non-trivial initialization that can take 5-10 seconds. But he hasn't complained yet, so we haven't pursued it further.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hnasarat
              wrote on last edited by
              #6

              I, too, am running into this problem.
              The only work-around I've found is to apply the stylesheet to the root object in designer. Thankfully my project has <15 ui files, so this is manageable.

              I found two bug reports about this issue, but no fix has been released yet, unfortunately:
              https://bugreports.qt-project.org/browse/QTBUG-2047
              https://bugreports.qt-project.org/browse/QTBUG-517

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rmam
                wrote on last edited by
                #7

                Although nearly 8 years have passed since this topic was created, it appears that no progress was made in implementing this feature.

                Here's a link to the relevant Qt Designer's bug report: Add support for external style sheets in Qt Widget Designer.

                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