Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to mix two colors represented by QColor type ?

How to mix two colors represented by QColor type ?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 7.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sibislaw2
    wrote on last edited by
    #1

    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;

    c=a+b@

    1 Reply Last reply
    1
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      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;
      c.setRgb(a.red(),b.green(),0);
      @

      So c becomes yellow.

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ankursaxena
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giordi
          wrote on last edited by
          #4

          This is how I usually blend two QColors togheter

          QColor(
          color1.red()* (1-r) + color2.red()r,
          color1.green()
          (1-r) + color2.green()r,
          color1.blue()
          (1-r) + color2.blue()*r,
          255));

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

          Coding is powaaaaa

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved