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
Qt Code:
  1. #ifndef IMAGEVIEWER_H
  2. #define IMAGEVIEWER_H
  3. #include<QtWidgets>
  4.  
  5. class ImageViewer : public QMainWindow
  6. {
  7. Q_OBJECT
  8. public:
  9. ImageViewer();
  10. public slots:
  11. void ouvrir();
  12. private:
  13. QLabel *label;
  14. QImage *image;
  15. QVBoxLayout *layout;
  16. };
  17.  
  18. #endif // IMAGEVIEWER_H
To copy to clipboard, switch view to plain text mode 
imageViewer.cpp
Qt Code:
  1. #include "imageviewer.h"
  2.  
  3. ImageViewer::ImageViewer(): QMainWindow()
  4. {
  5. label = new QLabel(this);
  6.  
  7. label->move(100,100);
  8. layout = new QVBoxLayout(this);
  9. layout->addWidget(label);
  10. this->setLayout(layout);
  11. QMenu *fichier = menuBar()->addMenu("Fichier");
  12. QMenu *edition = menuBar()->addMenu("Edition");
  13.  
  14. QAction *ouvrir = new QAction("Ouvrir",this);
  15. fichier->addAction(ouvrir);
  16. connect(ouvrir,SIGNAL(triggered(bool)),this,SLOT(ouvrir()));
  17.  
  18. }
  19.  
  20. void ImageViewer::ouvrir()
  21. {
  22. QString nomFichier = QFileDialog::getOpenFileName(this,"Open file", "C://");
  23.  
  24. QPixmap p(nomFichier);
  25. label->setPixmap(nomFichier);
  26.  
  27. }
To copy to clipboard, switch view to plain text mode 
thank you