#include#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton button("Click me!"); // Set the background color of the button to red QColor red = QColor::redF(); QPalette palette; palette.setColor(QPalette::Button, red); button.setPalette(palette); button.show(); return app.exec(); }
#includeIn this example, we use the redF method to create a red color, and then use the rgb() method to get its RGB components. We also create a green color using the RGB values directly. Then, we add the RGB components of the red and green colors together to create a new color (yellow). We output the RGB components of the resulting yellow color to the console. Package/Library: Qt framework's QColor class library.#include int main() { QColor red = QColor::redF(); QColor green(0, 1, 0); // Green color constructor // Combine the red and green colors to make a yellow color QColor yellow = red.rgb() + green.rgb(); // Output the yellow color components std::cout << "Red: " << yellow.redF() << std::endl; std::cout << "Green: " << yellow.greenF() << std::endl; std::cout << "Blue: " << yellow.blueF() << std::endl; return 0; }