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 do you get the window and text color from a qss stylesheet

How do you get the window and text color from a qss stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 949 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.
  • T Offline
    T Offline
    TeamGregor
    wrote on last edited by
    #1

    The program I am contributing to, determines the icon color depending on this.

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

      Hi,

      It's usually the other way around, you grab that information, insert it in your QSS and then apply it.

      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
      • T Offline
        T Offline
        TeamGregor
        wrote on last edited by
        #3

        Yeah, but I'm asking for the reverse

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

          So you want to parse the style sheet to find the information ?

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

          T 1 Reply Last reply
          0
          • SGaistS SGaist

            So you want to parse the style sheet to find the information ?

            T Offline
            T Offline
            TeamGregor
            wrote on last edited by
            #5

            @SGaist
            Yes, I do

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SimonSchroeder
              wrote on last edited by
              #6

              On first thought, I don't think you need to do anything with the style sheet directly. I suspect that you want to show your icon on a button or label. So, first create that button or label and try to figure out what the respective colors are for this widget.

              https://doc.qt.io/qt-6/stylesheet.html says the following at the end:

              When a style sheet is active, the QStyle returned by QWidget::style() is a wrapper "style sheet" style, not the platform-specific style. The wrapper style ensures that any active style sheet is respected and otherwise forwards the drawing operations to the underlying, platform-specific style (e.g., QWindowsVistaStyle on Windows).

              Maybe the QStyle of your label/button will help here. But, on first look, I didn't find any information how to extract the colors from the QStyle.

              T 1 Reply Last reply
              0
              • S SimonSchroeder

                On first thought, I don't think you need to do anything with the style sheet directly. I suspect that you want to show your icon on a button or label. So, first create that button or label and try to figure out what the respective colors are for this widget.

                https://doc.qt.io/qt-6/stylesheet.html says the following at the end:

                When a style sheet is active, the QStyle returned by QWidget::style() is a wrapper "style sheet" style, not the platform-specific style. The wrapper style ensures that any active style sheet is respected and otherwise forwards the drawing operations to the underlying, platform-specific style (e.g., QWindowsVistaStyle on Windows).

                Maybe the QStyle of your label/button will help here. But, on first look, I didn't find any information how to extract the colors from the QStyle.

                T Offline
                T Offline
                TeamGregor
                wrote on last edited by
                #7

                @SimonSchroeder

                I already can display the icon, I just need to get the color off the .qss for the widget thats it.

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SimonSchroeder
                  wrote on last edited by
                  #8

                  @TeamGregor said in How do you get the window and text color from a qss stylesheet:

                  @SimonSchroeder
                  I already can display the icon, I just need to get the color off the .qss for the widget thats it.

                  The QStyle of the button or label will have parsed the style sheet already and will give you the proper colors (if you can get the colors from the QStyle, which I didn't find quickly). The problem is that you can have multiple style sheets on multiple levels and Qt will combine them in the proper way. There is no way to query the combined style sheet at the current level.

                  If you want to instead use the colors you have in the main style sheet applied to the QApplication (and ignore any other style sheets), then I would suggest to just use those colors and not parse them back from the style sheet. The only reason to query them from the style sheet at runtime is if the user can somehow manipulate the colors. But then again, store the colors separately when the user changes them (if he does it through a UI).

                  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