0

I have different QLabels with the following stylesheet. Surprisingly, when they are disabled, the color changes, but not the font-size nor the font-weight. The font is always the one defined in QLabel (regardless of wether the label is enabled or not). Is there anything I missed?

setStyleSheet(QString(
            "QLabel{"
            "    font-family: %1; "
            "    font-size: 16px; "
            "    font-weight: bold; "
            "    color: %3; "
            "}"
            "QLabel::!enabled {"
            "    font-size: 12px; "
            "    font-weight: normal; "
            "    color: %2; "
            "}").arg(fontFamilyName).arg(MEDIUM_GREY).arg(SUPER_DARK_GREY));
laurapons
  • 971
  • 13
  • 32
  • Consider this [post](https://stackoverflow.com/questions/23490017/how-to-add-style-via-setstylesheet-without-losing-orignal-style-in-qt?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa) – Mohammad Kanan May 10 '18 at 18:41

1 Answers1

0

I would start by changing QLabel::!enabled with QLabel:disabled. Enabled and disabled are pseudo-states and according to the documentation here they are accessed with a single colon, not a double one.

Apart from that, you may still experience some Qt Style Sheets bugs (can't be sure since you didn't mention the Qt version you are using).

If after changing the !enabled to :disabled the problem is still present, I would suggest to try these workarounds:

Two workarounds which may work are:

  1. Set the font family in the !enabled part too, although it seems redundant;
  2. Set a background (e.g. background-color: transparent;

For more details about the possible Qt Style Sheet bugs you may face, I would suggest to have a look at the Qt bug tracker here.

Sergio Monteleone
  • 2,776
  • 9
  • 21
  • Yep... just tested with Qt 5.10.1... I think it's a indeed a Qt bug. You may file a bug report and see if they come with more suggestions. – Sergio Monteleone May 10 '18 at 17:45