VirtualBox

Ignore:
Timestamp:
Jan 3, 2024 5:09:21 PM (11 months ago)
Author:
vboxsync
Message:

FE/Qt: UICommon: Workaround for X11 dark themes; Make sure PlaceholderText foreground is distinguishable from Base background.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICommon.cpp

    r102751 r102752  
    11411141        qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2b2b2b; border: 1px solid #737373; }");
    11421142    }
    1143 #endif /* VBOX_WS_WIN */
     1143
     1144#else /* Linux, BSD, Solaris */
     1145
     1146    /* For the Dark mode! */
     1147    if (isInDarkMode())
     1148    {
     1149        // WORKAROUND:
     1150        // Have seen it on Linux with Qt5 but still see it with Qt6.
     1151        // In Dark themes on KDE (at least) PlaceholderText foreground
     1152        // is indistinguishable on Base background.
     1153
     1154        /* Acquire global palette: */
     1155        QPalette darkPalette = qApp->palette();
     1156
     1157        /* Get text base color: */
     1158        const QColor base = darkPalette.color(QPalette::Active, QPalette::Base);
     1159
     1160        /* Get possible foreground colors: */
     1161        const QColor simpleText = darkPalette.color(QPalette::Active, QPalette::Text);
     1162        const QColor placeholderText = darkPalette.color(QPalette::Active, QPalette::PlaceholderText);
     1163        QColor lightText = simpleText.black() < placeholderText.black() ? simpleText : placeholderText;
     1164        QColor darkText = simpleText.black() > placeholderText.black() ? simpleText : placeholderText;
     1165        if (lightText.black() > 128)
     1166            lightText = QColor(Qt::white);
     1167        lightText = lightText.darker(150);
     1168        if (darkText.black() < 128)
     1169            darkText = QColor(Qt::black);
     1170        darkText = darkText.lighter(150);
     1171
     1172        /* Measure base luminance: */
     1173        double dLuminance = (0.299 * base.red() + 0.587 * base.green() + 0.114 * base.blue()) / 255;
     1174
     1175        /* Adjust color accordingly: */
     1176        darkPalette.setColor(QPalette::Active, QPalette::PlaceholderText,
     1177                             dLuminance > 0.5 ? darkText : lightText);
     1178
     1179        /* Put palette back: */
     1180        qApp->setPalette(darkPalette);
     1181    }
     1182
     1183#endif /* Linux, BSD, Solaris */
    11441184}
    11451185
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette