Qt 5.3.2 / OSX 10.9+ draw in device RGB on multiple monitors
-
Hi !
I work on an Application that needs to draw specific device RGB colors
to multiple monitors on OSX 10.9 using Qt 5.3.2.
If i just draw a QColor(240,120,60) to a Widget, this is measured
exactly as 240/120/60 on the primary monitor but if i create the same
widget on a secondary monitor is is measured e.g. 240/117/51 .
(One can use the Utility "Digital Color Meter" and be sure to switch to "native" values, if you choose sRGB or any of the other values the measurements will be identical or very close on the two monitors as this is the whole point of that unwanted magic).OSX tries to be smart ant to make the color on the second screen appear
as the color on the primary screen. While this is nice its not usable
for my Application.In former Qt / OSX versions we had this approach of subclassing a Widget and implementing the paintevent
(c_ containg the current RGB Values to be painted e.g. 240/120/60):void RGBFrame::paintEvent(QPaintEvent* e)
{
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
float components[4] = { 1.0, 1.0, 1.0, 1.0 };
components[0] = ((float)c_.red() * 1000 / 255) / 1000;
components[1] = ((float)c_.green() * 1000 / 255) / 1000;
components[2] = ((float)c_.blue() * 1000 / 255) / 1000;
CGColorRef color = CGColorCreate (colorSpaceRef, components);
CGRect cgrect = CGRectMake(e->rect().x(), e->rect().y(), e->rect().x() +
e->rect().width(), e->rect().y() + e->rect().height());
CGContextRef context = qt_mac_cg_context(this);
CGContextSetFillColorWithColor(context, color);
CGContextFillRect(context, cgrect);
CGColorRelease(color);
CGColorSpaceRelease(colorSpaceRef);
}i tried to upgrade this to Qt5 using QMac::currentCGContext() instead of
the no more available qt_mac_cg_context(this) but it simply does not work.Do you guys have a working or even more elegant approach ?
Greetings & thank you,
Nils Heidorn