#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; window.setWindowTitle("My Window"); QPushButton *button = new QPushButton("Click Me", &window); button->move(100, 50); window.show(); return app.exec(); }
#includeIn this example, we create an instance of QWidget called window, and add a QLabel to it. We load an image file "image.jpg" and set the pixmap of the label to it, using the setPixmap() method. We also set the alignment to center, using the setAlignment() method. Finally, we show the window and start the application event loop. Package/library: Qt5Widgetsint main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget window; QLabel *label = new QLabel(&window); QPixmap pixmap("image.jpg"); label->setPixmap(pixmap); label->setAlignment(Qt::AlignCenter); window.show(); return app.exec(); }