How to display local pictures in QT with label labels

Source: Internet
Author: User

#define Cimage_h
#include <QtGui/QDialog>
#include <QLabel>

Class Qlabel;
Class Qlineedit;
Class Qpushbutton;

Class Cimage:public Qdialog
{
Q_object
Public
CImage (Qwidget *parent=0);
Virtual ~cimage () {}
Private
Qlabel *imagelabel;
Qpushbutton *imagebutton;
Public Slots:
void Isertimage ();
};

#endif//Cimage_h


#include <QtGui/QtGui>
#include <QMovie>
#include "CImage.h"

Cimage::cimage (Qwidget *parent): Qdialog (parent)
{
Imagebutton=new Qpushbutton (TR ("browse"));
Imagelabel=new Qlabel (tr ("Picture"));
Qvboxlayout *vboxlayout=new qvboxlayout;
Vboxlayout->addwidget (Imagelabel);
Vboxlayout->addwidget (ImageButton);
SetLayout (vboxlayout);

Connect (imagebutton,signal (clicked ()), This,slot (Isertimage ()));
Setwindowtitle (tr ("Picture preview"));
Resize (200,300);
}

void Cimage::isertimage ()
{
Imagebutton=qobject_cast<qpushbutton*> (Sender ());
QString Filename=qfiledialog::getopenfilename (This,
TR ("Open File"),
"/usr/local/trolltech",
TR ("Any file (*. *)"
";; Text file (*.txt) "
";; XML file (*.xml) "
";; I Mages (*.png *.xpm *.jpg));
Qmovie *move=new Qmovie (fileName);

Imagelabel->setmovie (move);
Move->start ();
}


#include <QtGui/QtGui>
#include "CImage.h"

int main (int argc,char*argv[])
{
Qapplication app (ARGC,ARGV);
QTEXTCODEC::SETCODECFORTR (Qtextcodec::codecforname ("GB18030"));
CImage Dlg;
return Dlg.exec ();
}

How to display local pictures in QT with label labels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.