Hello,
i have an image and i want to display it but i don't want to fix the size of a QLabel, i want the QPixmap to be adjusted automatically with the QLabel and the QLabel also be adjusted dynamically according to the size of the window, i.e i want the QLabel to resize itself according to the resize of my QMainWindow in such way the QPixmap is also adjusted with QLabel
How can i do that please.
ImageViewer.h
#ifndef IMAGEVIEWER_H
#define IMAGEVIEWER_H
#include<QtWidgets>
{
Q_OBJECT
public:
ImageViewer();
public slots:
void ouvrir();
private:
};
#endif // IMAGEVIEWER_H
#ifndef IMAGEVIEWER_H
#define IMAGEVIEWER_H
#include<QtWidgets>
class ImageViewer : public QMainWindow
{
Q_OBJECT
public:
ImageViewer();
public slots:
void ouvrir();
private:
QLabel *label;
QImage *image;
QVBoxLayout *layout;
};
#endif // IMAGEVIEWER_H
To copy to clipboard, switch view to plain text mode
imageViewer.cpp
#include "imageviewer.h"
{
label->move(100,100);
layout->addWidget(label);
this->setLayout(layout);
QMenu *fichier
= menuBar
()->addMenu
("Fichier");
QMenu *edition
= menuBar
()->addMenu
("Edition");
fichier->addAction(ouvrir);
connect(ouvrir,SIGNAL(triggered(bool)),this,SLOT(ouvrir()));
}
void ImageViewer::ouvrir()
{
label->setPixmap(nomFichier);
}
#include "imageviewer.h"
ImageViewer::ImageViewer(): QMainWindow()
{
label = new QLabel(this);
label->move(100,100);
layout = new QVBoxLayout(this);
layout->addWidget(label);
this->setLayout(layout);
QMenu *fichier = menuBar()->addMenu("Fichier");
QMenu *edition = menuBar()->addMenu("Edition");
QAction *ouvrir = new QAction("Ouvrir",this);
fichier->addAction(ouvrir);
connect(ouvrir,SIGNAL(triggered(bool)),this,SLOT(ouvrir()));
}
void ImageViewer::ouvrir()
{
QString nomFichier = QFileDialog::getOpenFileName(this,"Open file", "C://");
QPixmap p(nomFichier);
label->setPixmap(nomFichier);
}
To copy to clipboard, switch view to plain text mode
thank you
Bookmarks