Hi,
I subclassed QLabel so that it supports the clicked() event and I'm trying to create a small image viewer.
The problem is that my setImage function is not receiving the image properly from the connect statement. Instead of actually setting the image, the QLabel sets itself blank (ie it doesnt show anything). I would really appreciate any help on what am I doing wrong.
// connecting signal
connect(labels[imagenum], SIGNAL(clicked(QPixmap&)), this, SLOT(setImage(QPixmap&)));
void MainWindow
::setImage(QPixmap &pic
) {
// mainimage is a QLabel
mainimage->setPixmap(pic);
mainimage->repaint();
}
// connecting signal
connect(labels[imagenum], SIGNAL(clicked(QPixmap&)), this, SLOT(setImage(QPixmap&)));
void MainWindow::setImage(QPixmap &pic)
{
// mainimage is a QLabel
mainimage->setPixmap(pic);
mainimage->repaint();
}
To copy to clipboard, switch view to plain text mode
// imagelabel.cpp
#include <QtGui>
#include "imagelabel.h"
{
connect(this, SIGNAL(clicked(QPixmap&)), this, SLOT(slotClicked()));
}
void ImageLabel::slotClicked()
{
qDebug() << "clicked";
}
{
emit clicked(local_pixmap);
}
// imagelabel.cpp
#include <QtGui>
#include "imagelabel.h"
ImageLabel::ImageLabel(QWidget *parent) : QLabel(parent)
{
connect(this, SIGNAL(clicked(QPixmap&)), this, SLOT(slotClicked()));
}
void ImageLabel::slotClicked()
{
qDebug() << "clicked";
}
void ImageLabel::mousePressEvent(QMouseEvent *event)
{
emit clicked(local_pixmap);
}
To copy to clipboard, switch view to plain text mode
// imagelabel.h
#ifndef IMAGELABEL_H
#define IMAGELABEL_H
#include <QLabel>
class ImageLabel
: public QLabel{
Q_OBJECT
public:
~ImageLabel() {}
signals:
void clicked(QPixmap&);
public slots:
void slotClicked();
protected:
private:
};
#endif // IMAGELABEL_H
// imagelabel.h
#ifndef IMAGELABEL_H
#define IMAGELABEL_H
#include <QLabel>
class ImageLabel : public QLabel
{
Q_OBJECT
public:
ImageLabel (QWidget *parent = 0);
~ImageLabel() {}
signals:
void clicked(QPixmap&);
public slots:
void slotClicked();
protected:
void mousePressEvent(QMouseEvent *event);
private:
QPixmap local_pixmap;
};
#endif // IMAGELABEL_H
To copy to clipboard, switch view to plain text mode
Thanks a lot in advance for your help!
Bookmarks