Important: Please read the Qt Code of Conduct -

How to mix two colors represented by QColor type ?

  • 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;


  • Moderators


    You can't do it by adding. There's no overloaded "+" operator for QColor.
    Instead you can try this,
    QColor a(Qt::red);
    QColor b(Qt::green);

    QColor c;

    So c becomes yellow.

  • 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.

  • This is how I usually blend two QColors togheter

    QColor(* (1-r) +,
    (1-r) +,
    (1-r) +*r,

    where r is the ratio of the color for example 0.5 will give you a 50-50 blend

Log in to reply