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 create a QStyle from a `.css` file?
Forum Updated to NodeBB v4.3 + New Features

How to create a QStyle from a `.css` file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 730 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.
  • S Offline
    S Offline
    Sauntor
    wrote on last edited by
    #1

    There exists QApplication::setStyleSheet() and QWidget::setStyleSheet(), but I can't find a way to create a QStyle from a .css file, I want to make a QStyle with some styles predefined in a .css file and some others computed at runtime.
    So, is there a way to achieve it?

    C JonBJ 2 Replies Last reply
    1
    • S Sauntor

      There exists QApplication::setStyleSheet() and QWidget::setStyleSheet(), but I can't find a way to create a QStyle from a .css file, I want to make a QStyle with some styles predefined in a .css file and some others computed at runtime.
      So, is there a way to achieve it?

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

      @Sauntor Qt Style Sheets are not CSS although there is some similarity.

      Assuming you put some valid Qt style sheet rules in a text file, or resource, then all you need to do is open the file, read the content into a string, and call setStylesheet() with the string. There's no great mystery involved.

      Edit: QStyle is an abstract class used only to build concrete classes implementing styles. These are not run-time creatable entities.

      1 Reply Last reply
      2
      • S Sauntor

        There exists QApplication::setStyleSheet() and QWidget::setStyleSheet(), but I can't find a way to create a QStyle from a .css file, I want to make a QStyle with some styles predefined in a .css file and some others computed at runtime.
        So, is there a way to achieve it?

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

        @Sauntor
        There isn't a way to do this. Other than coding whatever you want manually by inspecting the CSS and finding equivalents. And CSS has rules/selectors for when to apply its content, there is no equivalent for that with QStyle, again you have to code it yourself.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          To add to my fellows, are you thinking of something like the style that is used when you call setStyleSheet ?

          If so, you will to write the parser yourself and also be aware that not everything that is defined in the CSS specification can be applied to desktop controls.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

            @ChrisW67 @JonB @SGaist Thanks, to all of you😘

            1 Reply Last reply
            0
            • N Offline
              N Offline
              NeerajMehta
              wrote on last edited by
              #6
              This post is deleted!
              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