QT中用label标签显示本地图片的方法

#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("浏览"));
ImageLabel=new QLabel(tr("图片"));
QVBoxLayout *vboxLayout=new QVBoxLayout;
vboxLayout->addWidget(ImageLabel);
vboxLayout->addWidget(ImageButton);
setLayout(vboxLayout);

connect(ImageButton,SIGNAL(clicked()),this,SLOT(IsertImage()));
setWindowTitle(tr("图片预览"));
resize(200,300);
}

void CImage::IsertImage()
{
ImageButton=qobject_cast<QPushButton*>(sender());
QString fileName=QFileDialog::getOpenFileName( this,
tr("打开文件"),
"/usr/local/Trolltech",
tr("任何文件(*.*)"
";;文本文件(*.txt)"
";;XML文件(*.xml)"
";;Images (*.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();
}

 

转载于:https://www.cnblogs.com/YunChao/p/5547300.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值