参考链接:
1、http://blog.csdn.net/feiyangyangfei/article/details/8672748
Qt信号与槽 以及图像在label缩放显示
//mysignal.h
#ifndef MYSIGNAL_H
#define MYSIGNAL_H
#include <QObject>
#include <QString>
#include <QImage>
#include <QLabel>
#include <QPixmap>
#include <QPainter>
#include <QMessageBox>
class MySignal : public QObject
{
Q_OBJECT
public:
MySignal(QObject *parent);
~MySignal();
//槽
public slots:
void MysetValue(int valueX);
bool MyloadImage(QString imagePath);
void MyShowImage(QLabel *showImageLabel);
signals:
void MyClicked(int valueX);
private:
int m_valueInt;
QImage m_ImageClass;
};
#endif // MYSIGNAL_H
//mysignal.cpp
#include "mysignal.h"
MySignal::MySignal(QObject *parent)
: QObject(parent)
{
QObject::connect(this,SIGNAL(MyClicked(int)),this,SLOT(MysetValue(int)));
//QObject::connect(this,SIGNAL(MySignal(int,int)),this,SLOT(MySlot(int,int)));
}
MySignal::~MySignal()
{
}
void MySignal::MysetValue(int valueX)
{
m_valueInt = valueX;
//emit MyClicked(valueX);容易死循环
}
bool MySignal::MyloadImage(QString imagePath)
{
if (imagePath.trimmed().isEmpty()) return false;
if (!m_ImageClass.load(imagePath)) return false;
QMessageBox::information(NULL,"Information","image load scuccess!",QMessageBox::Yes|QMessageBox::No);
}
void MySignal::MyShowImage(QLabel *showImageLabel)
{
QPixmap myPixmap;
QSize labelSize = showImageLabel->size();
QImage tepImage = m_ImageClass.scaled(labelSize);
myPixmap.convertFromImage(tepImage);
showImageLabel->setPixmap(myPixmap);
}