refresh a QLabel and QImage
Hello,
i have a serious problem, when i choose an image to display in a Qwidget (fentroi), it is displayed but the problem when i choose another it can't refresh and it can't display the new image, ,and im working on binarisation and the threshold didn't refresh too i assume that because the QImage that i load is the cause because it dosen't refresh too.
here my code
fenetrePrincipale.h (MainWindow)
Code:
#ifndef FENETREPRINCIPALE_H
#define FENETREPRINCIPALE_H
#include <QtWidgets>
#include "traitement.h"
{
Q_OBJECT
public :
FenetrePrincipale();
public slots :
void ouvrir();
void traiter();
void traiterOtsu();
private:
};
#endif // FENETREPRINCIPALE_H
fenetrePricipale.cpp
Code:
#include "traitement.h"
#include "otsu.h"
#include "fenetreprincipale.h"
{
QMenu *menuFichier
= menuBar
()->addMenu
("Fichier");
menuFichier->addAction(actionOuvrir);
menuFichier->addAction(actionQuitter);
QMenu *menuTraitement
= menuBar
()->addMenu
("Traitement");
menuTraitement->addAction(actionBinarisation);
QObject::connect(actionOuvrir,
SIGNAL(triggered
(bool)),
this,
SLOT(ouvrir
()));
QObject::connect(actionQuitter,
SIGNAL(triggered
(bool)),
this,
SLOT(close
()));
QObject::connect(actionBinarisation,
SIGNAL(triggered
(bool)),
this,
SLOT(traiterOtsu
()));
QObject::connect(this,
SIGNAL(changer
()),
this,
SLOT(afficher
()));
}
void FenetrePrincipale::ouvrir()
{
nomFichier
= QFileDialog::getOpenFileName(this, tr
("Open File"),
"C:/Users/amine/Downloads");
label->setGeometry(100,100,400,400);
pixmap.convertFromImage(image1);
label->setPixmap(pixmap);
fentroi.show(); // fentroi (fenetre qui affiche l'image) attribut de fenetre principale
label->update();
}
void FenetrePrincipale::traiterOtsu()
{
OtsuAlgo traitement(nomFichier);
traitement.binarisation();
label->setGeometry(100,100, 400, 400);
label
->setPixmap
(QPixmap::fromImage(*im
));
lcd->move(70,70);
lcd->display(traitement.getSeuil());
fenSec.show();
}
please if someone can help me and thanks
Re: refresh a QLabel and QImage
Your code keeps creating a new label every time it want to update the image. You should be calling setPixmap() on the same QLabel every time.
Re: refresh a QLabel and QImage
Thanks a lot Mr ChrisW67 :)
Re: refresh a QLabel and QImage
And you don't want to leak the image by allocating it on the heap like you do right now in line 44.
Cheers,
_