Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the color of a window's frame?

Tags:

windows

styles

qt

I'm trying to read the color of a window's border (frame) of a regular window.

It seems that window->palette().color(QPalette::XXXX) would do it, but what's XXXX? or is it not possible with palette? If so, how?

like image 461
tru7 Avatar asked Jan 31 '26 02:01

tru7


1 Answers

You need to use it the native GetSysColorBrush function:

QColor getWindowFrameColor() {
    // This is the only way to detect that a given color is supported
    HBRUSH brush = GetSysColorBrush(COLOR_ACTIVEBORDER);
    if (brush) {
        DWORD color = GetSysColor(COLOR_ACTIVEBORDER);
        return QColor(GetRValue(color), GetGValue(color), GetBValue(color));
        // calling DeleteObject(brush) is unnecessary, but would be harmless
    }
    return QColor();
}

I've searched the Qt sources for COLOR_ACTIVEBORDER, and the only other way to retrieve it would be by running some custom javascript code on WebKit.

like image 72
Kuba hasn't forgotten Monica Avatar answered Feb 01 '26 16:02

Kuba hasn't forgotten Monica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!