[Interest] How to get active button color in macOS?

Patrick Stinson patrickkidd at gmail.com
Wed Jan 30 13:18:08 CET 2019

That was also my estimation. I decided to go with native code:

    #ifdef Q_OS_MACOS
QColor qt_mac_toQColor(const NSColor *color) const
    QColor qtColor;
    NSString *colorSpace = [color colorSpaceName];
    if (colorSpace == NSDeviceCMYKColorSpace) {
        CGFloat cyan, magenta, yellow, black, alpha;
        [color getCyan:&cyan magenta:&magenta yellow:&yellow black:&black alpha:&alpha];
        qtColor.setCmykF(cyan, magenta, yellow, black, alpha);
    } else {
        NSColor *tmpColor;
	tmpColor = [color colorUsingColorSpaceName:NSDeviceRGBColorSpace];
        CGFloat red, green, blue, alpha;
        [tmpColor getRed:&red green:&green blue:&blue alpha:&alpha];
        qtColor.setRgbF(red, green, blue, alpha);
    return qtColor;

    QColor appleControlAccentColor() const {
        if (@available(macOS 10.14, *)) {
            // macOS 10.14 or later code path                                                                                                                                                                   
            return qt_mac_toQColor([NSColor controlAccentColor]);
        } else {                                                                                                                                                                   
	    return QApplication::palette().color(QPalette::Active, QPalette::ButtonText);

> On Jan 30, 2019, at 2:53 AM, Nils Jeisecke <nils.jeisecke at saltation.com> wrote:
> Hi,
> Am 30.01.2019 um 02:27 hat Patrick Stinson geschrieben:
>> Hello!
>> I am trying to figure out how to get the following color for macOS
>> (see screenshot) which is called “Accent Color" in the General section
>> of System Preferences.
> I'm afraid there's only the "highlight" color available (which is derived
> from the accent color by default but can be changed). You can use native
> API to get the accent color.
> Qt palette is kind of stuck at representing Windows 95 like UIs, it has
> even color values for drawing fancy grayish 3D buttons ;-)
> Given that Windows 10 also has some kind of accent color I would welcome
> an additional palette entry. This could be the same value as highlight
> on platforms that don't support accent colors.
> On systems with accent color support usually the "accent color" is
> used for list selection, toggles, checkboxes and control indicator
> styling (like the open button of a combobox). "highlight" is meant for
> user selection in input fields etc.
> I'm not sure if adding another color entry is possible in Qt5 though.
> Nils

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20190130/e09b7617/attachment.html>

More information about the Interest mailing list