In CMake, add/link the Carbon
library to the executable
FIND_LIBRARY(CARBON_LIBRARY Carbon)
set(EXTRA_LIBS
${CARBON_LIBRARY}
Make sure to add ${CARBON_LIBRARY}
in the TARGET_LINK_LIBRARIES
call for the executable.
Then create a file to hold the Object-C code, in this case 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:0.];
}
Make sure to add the file to your source code files in your CMake project. Then define the function in your code like so:
extern "C" void changeTitleBarColor(WId winId, double red, double green, double blue);
And then call the function, ideally in your MainWindow constructor like so:
changeTitleBarColor(winId(), 245./255., 29./255., 46./255.);