[Development] Function to merge two QColor?
Kai Uwe Broulik
kde at privat.broulik.de
Sun Nov 23 20:26:57 CET 2025
Hi,
Qt Quick has Qt.tint but I don’t see an equivalent in QColor. Perhaps a
C++ API should be added. In any case, it’s trivial, just doing alpha
blending:
QColor QQuickColorValueType::tint(const QColor &tintColor) const
{
int tintAlpha = tintColor.alpha();
if (tintAlpha == 0xFF)
return tintColor;
else if (tintAlpha == 0x00)
return *this;
// tint the base color and return the final color
const QColor baseColor = QColor::toRgb();
const qreal a = tintColor.alphaF();
const qreal inv_a = 1.0 - a;
const qreal r = tintColor.redF() * a + baseColor.redF() * inv_a;
const qreal g = tintColor.greenF() * a + baseColor.greenF() * inv_a;
const qreal b = tintColor.blueF() * a + baseColor.blueF() * inv_a;
return QColor::fromRgbF(r, g, b, a + inv_a * baseColor.alphaF());
}
Cheers
Kai Uwe
Am 23.11.25 um 20:17 schrieb Christian Ehrlicher via Development:
> Hi,
>
> for the window11 style plugin I like to merge two QColors to avoid a
> double painting. The first color has no alpha but the second. Is there
> anything ready to use in Qt (internals) or do I have to write something
> by my own?
>
>
> Thx,
> Christian
More information about the Development
mailing list