如何把QLabel改成按钮 !!!
#include "widget.h"
#include "ui_widget.h"
#include<QPushButton>
#include<QBitmap>
#include<QPixmap>
#include <QMouseEvent>
#include <QMessageBox>
#include <QLabel>
#include<QDebug>
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QPixmap pm; pm.load(":/picture/Image/s.png");
ui->label->setGeometry(0,0,pm.width(), pm.height());
ui->label->setPixmap(pm);
int i=connect(this, SIGNAL(clicked()), this, SLOT(slotClicked())); //信号连接
qDebug()<<i<<endl;
}
Widget::~Widget()
{
delete ui;
}
void Widget::mousePressEvent(QMouseEvent *e)
{
int x = e->x();
int y = e->y();
//假如在QRect( 0, 0, 48, 48 )这个区域里(图片大小为48X48),就发出信号
if (x>0 && x<48 && y>0 && y<48){
emit clicked();
}
}
void Widget::slotClicked()
{
QMessageBox::about( this, "Mouse Example", "You have pressed mouse, exit now!");
close();
}