#include#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QPixmap image("myimage.jpg"); // load the image file QLabel label; label.setPixmap(image); // set the pixmap as label's content label.show(); return app.exec(); }
#include#include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QPixmap image("myimage.jpg"); // load the image file QSize newSize(200, 200); QPixmap scaledImage = image.scaled(newSize, Qt::AspectRatioMode::KeepAspectRatio); QLabel label; label.setPixmap(scaledImage); // set the resized pixmap as label's content label.show(); return app.exec(); }
#includeThe QPixmap class is part of the QtGui package in Qt library.#include #include #include int main(int argc, char *argv[]) { QApplication app(argc, argv); QImage img("myimage.jpg"); // load the image file as QImage QPixmap pixmap = QPixmap::fromImage(img); // create a QPixmap from the QImage QLabel label; label.setPixmap(pixmap); // set the pixmap as label's content label.show(); return app.exec(); }