How to set the NSColorSpace for a QMainWindow
-
On MacOS, we used to be able to set the display colorspace on the QMainWindow for our application to allow it to display HDR images on Qt 5.12.8. Since updating to Qt 5.15.2 the following code on a QMainWindow after creation doesn't seem to set the colorspace correctly any more, it seems to revert to NSColorSpace.sRGBColorSpace.
NSView* view = reinterpret_cast<NSView *>(winId()); view.window.colorSpace = NSColorSpace.displayP3ColorSpace;
Does anyone knows how we're supposed to be setting the display colorspace these days? Thanks.
-
Hi,
When are you doing that ?
Did you check if the value is nil before setting it ? If that's the case, I would guess that you are changing the property too early. -
@SGaist said in How to set the NSColorSpace for a QMainWindow:
Hi,
When are you doing that ?
Did you check if the value is nil before setting it ? If that's the case, I would guess that you are changing the property too early.Setting that on creation of the window object derived from QMainWindow.
view.window.colorSpace isn't nil at that point, it's set to "Pro Display XDR colorspace" for my dev setup, it's probably different for the display that the app started on. -
Can you provide a minimal compilable example to test that ?
By the way, which version of macOS are you on ? -
I'm on Monterey, we had bug reports and QA testing on Catalina and Big Sur. Not sure if I can provide an example. I'll need to work on one.
Technically though it's a hack dated back to the days of 15.12.1. We picked up the fix by merging changes from these files+version,https://code.qt.io/cgit/qt/qtbase.git/tree/src/plugins/platforms/cocoa/qcocoabackingstore.mm?h=5.12.8
https://code.qt.io/cgit/qt/qtbase.git/tree/src/plugins/platforms/cocoa/qiosurfacegraphicsbuffer.mm?h=5.12.8If there is a more modern, OS portable way to set the display colorspace for an app, I'd rather use that.