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 add a centralized stylesheet definition to a project?

How to add a centralized stylesheet definition to a project?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.2k 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.
  • R Offline
    R Offline
    rmam
    wrote on last edited by
    #1

    I'm working on a project which uses custom stylesheets extensively. Instead of adding a stylesheet definition per widget, can anyone tell me if there is any way to store all stylesheet definitions in a single file and get Qt Creator and all widgets to follow them?

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

      Hi
      Stylesheets are cascading meaning you can set one style sheet to QApplication and it will
      affect all Widgets in the application. This is much easier to manage than many stylesheets all over the widgets.
      But this is only at runtime.

      During Design time, you can set same style sheet on MainWindow ( or what ever is the top widget) and
      all its children are affected but if you create a new form, then it wont automatically
      get a/the stylesheet. I also missed that feature.

      So yes, you can use one file and apply it exactly once but only run time.

      Its more fiddle, fiddle when in Designer.

      That said, the UI files are just xml files so its quite easy to use a cmdline tool like
      http://xmlstar.sourceforge.net/overview.php
      and auto add a stylesheet for all UI files if its a must to see the right look in Designer
      and then when "ready" strip all UI files for stylesheets and
      only set via application so you can get the benefit of one file for all styles.

      That said again ;), stylesheets was meant for smaller tweaks.
      For a custom look, QStyle offer far better performance and absolute control.
      http://doc.qt.io/qt-5/qtwidgets-widgets-styles-example.html

      1 Reply Last reply
      1

      • Login

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