Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to mix two colors represented by QColor type ?
sibislaw2 last edited by
Hi, i want to mix two colors represented by QColor type in my C++ code. How to do it 'simple way' ? Like
@QColor a, b, c;
You can't do it by adding. There's no overloaded "+" operator for QColor.
Instead you can try this,
So c becomes yellow.
ankursaxena last edited by
Actually when you use color in qt. It is already mixture of 3 colors based on rgb or any other system.
If you are using rgb system then there will be 3 colors mixture.
Example taken by p3c0 is showed that there are 3 colors one is Qt::red, second is Qt::green and third one and last is 0 means black.
So it is mixture of red,green and black.
giordi last edited by
This is how I usually blend two QColors togheter
color1.red()* (1-r) + color2.red()r,
color1.green() (1-r) + color2.green()r,
color1.blue() (1-r) + color2.blue()*r,
where r is the ratio of the color for example 0.5 will give you a 50-50 blend