Changing window titlebar colour in macOS



  • Hi, I would like to change the colour of the window titlebar on OSX/macOS.

    Does anyone have a route to do that ? My Cocoa/Objective C skills are not so strong; I'm thinking

    QWidget::winId() gets me an NSView, use [nsview window] to get an NSWindow and then window.titlebarAppearsTransparent = true; window.backgroundColor = my_colour; but it seems to me that I would need to access some Qt internals that are not exposed to me.


  • Qt Champions 2017

    Hi
    Qt do not draw or handle the title bar on any platform.
    Im 100% macintosh noob so might be different on that OS but on windows or
    linux you cannot directly from Qt change the color as it not controlled by Qt at all.



  • Hi mrjj,

    My understanding is that Qt wraps native widgets as much as possible so I am looking for way to effect a titlebar colour change in a Qt friendly way.

    If I can access the native elements, such as with QWidget::winId() then maybe it's possible to do it but I don't know enough about Mac and Objective C which is why I am asking here.



  • If anyone still searches a solution to this - here some tested code (Qt 5.10, macOS High Sierra):

    changetitlebarcolor.mm:

    #include <QWidget>
    #import <Cocoa/Cocoa.h>
    
    extern "C" void changeTitleBarColor(WId winId, double red, double green, double blue) {
        if (winId == 0) return;
        NSView* view = (NSView*)winId;
        NSWindow* window = [view window];
        window.titlebarAppearsTransparent = YES;
        window.backgroundColor = [NSColor colorWithRed:red green:green blue:blue alpha:1.];
    }
    

    In your main window class:

    extern "C" void changeTitleBarColor(WId winId, double red, double green, double blue);
    
    MainWindow::MainWindow() {
        changeTitleBarColor(winId(), 15./255., 29./255., 46./255.);
    

    This example will change the title bar color to a dark blue...


Log in to reply
 

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