#include#include // create a label QLabel *label = new QLabel("Image"); // create a pixmap from a file QPixmap pixmap("/path/to/image.jpg"); // set the pixmap on the label label->setPixmap(pixmap);
#includeIn this example, a QLabel widget is created with the text "Image". A QPixmap object is created dynamically with a size of 200x200 pixels, and filled with the color red. The setPixmap method is called on the label object to set the image. Package/library: Qt framework.#include // create a label QLabel *label = new QLabel("Image"); // create a pixmap dynamically QPixmap pixmap(200, 200); pixmap.fill(Qt::red); // set the pixmap on the label label->setPixmap(pixmap);