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

  • Is there a way to get it without regexping styleSheet?

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


    QLabel {
    	color: white;
    QLabel#special_color:hover {
    	color: green;

  • Moderators

    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:


  • @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?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.