Ask Your Question

Revision history [back]

To show an image in your Qt project, you can use the QLabel widget and set its pixmap to your image. Here's an example:

  1. First, include the QLabel header file in your code:
#include <QLabel>
  1. Create a QLabel widget and set its pixmap to your image:
QLabel *imageLabel = new QLabel(this);
imageLabel->setPixmap(QPixmap(":/path/to/image.png"));

Note that the image file path is specified as a Qt resource file path using the "qrc" protocol. You can add the image file to your Qt resource file by right-clicking on the file in the "Project" view and selecting "Add New... -> Qt -> Qt Resource File".

  1. Set the size and position of the QLabel widget:
imageLabel->setGeometry(10, 10, 100, 100);

This example sets the position of the widget to (10, 10) and the size to 100x100 pixels.

  1. Add the QLabel widget to your main window or other container widget:
imageLabel->show();

This will display the image in your Qt project.