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 get color of a QLabel.setObjectName("special_color") from palette?
Forum Updated to NodeBB v4.3 + New Features

How to get color of a QLabel.setObjectName("special_color") from palette?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 821 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.
  • P Offline
    P Offline
    porsol
    wrote on last edited by
    #1

    Is there a way to get it without regexping styleSheet?

    label = QLabel()
    # color of normal QLable (white)
    color = label.palette().color(QPalette.Text)
    
    label.setObjectName("special_color")
    #color = ?
    

    styleSheet

    QLabel {
    	color: white;
    }
    QLabel#special_color:hover {
    	color: green;
    }
    
    raven-worxR 1 Reply Last reply
    0
    • P porsol

      Is there a way to get it without regexping styleSheet?

      label = QLabel()
      # color of normal QLable (white)
      color = label.palette().color(QPalette.Text)
      
      label.setObjectName("special_color")
      #color = ?
      

      styleSheet

      QLabel {
      	color: white;
      }
      QLabel#special_color:hover {
      	color: green;
      }
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @porsol
      The way is the same is the same. After setting the object-name the widget needs to be polished though, so the stylesheet is reapplied. In C++ the following can be done:

      widget->style()->polish(widget);
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      P 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @porsol
        The way is the same is the same. After setting the object-name the widget needs to be polished though, so the stylesheet is reapplied. In C++ the following can be done:

        widget->style()->polish(widget);
        
        P Offline
        P Offline
        porsol
        wrote on last edited by porsol
        #3

        @raven-worx
        Basically I write my own QLabel, because native QLabel doesn't support things I need. So before drawing text, I wanted to get its color(special_color) from stylesheet.
        Can I get it through QPalette?
        It must be stored somewhere in memory but the actual css file, no?

        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