QColor color(255, 0, 0); // create a QColor object with (R, G, B) values int hue, sat, val; // variables to store Hue, Saturation, Value color.getHsv(&hue, &sat, &val); // get Hue, Saturation, Value values of the color std::cout << "Hue: " << hue << " Saturation: " << sat << " Value: " << val << std::endl;
QColor color(150, 200, 100); // create a QColor object with (R, G, B) values int hue, sat, val; // variables to store Hue, Saturation and Value of the color color.getHsv(&hue, &sat, &val); //get HSV values of color hue = (hue + 180) % 360; // calculate hue value of complementary color QColor compColor = QColor::fromHsv(hue, sat, val); // create complementary QColor std::cout << "Complementary color R: " << compColor.red() << " G: " << compColor.green() << " B: " << compColor.blue() << std::endl;This example creates a QColor object with RGB values (150, 200, 100). Then getHsv function is used to obtain the HSV values of the color. The hue value of the complementary color is calculated by adding 180 degrees to the original hue and then wrapping it around to ensure it stays within 0-359 range. The complementary QColor object is then created using the calculated Hue, Saturation, and Value. The resulting complementary color is printed as R: 100 G: 100 B: 200. The package library used in these examples is Qt core library.