http://blog.csdn.net/tingsking18/article/details/4071619 我写的代码如下,点击button可以显示dialog对话框,点击label还是不行?哪位大侠指导下,谢谢。
#ifndef XIANSHIDUIHUAKUANG_H
#define XIANSHIDUIHUAKUANG_H
#include <QtGui/QWidget>
#include "ui_xianshiduihuakuang.h"
#include <QPushButton>
#include <QDialog>
#include <QLabel>
class xianshiduihuakuang : public QWidget
{
Q_OBJECT
public:
xianshiduihuakuang(QWidget *parent = 0, Qt::WFlags flags = 0);
~xianshiduihuakuang();
protected:
void mouseReleaseEvent(QMouseEvent *);
signals:
void Clicked(xianshiduihuakuang*clicked);
private:
Ui::xianshiduihuakuangClass ui;
QDialog *dialog;
void painUI();
private slots:
void shdl();
};
#endif // XIANSHIDUIHUAKUANG_H
#include "xianshiduihuakuang.h"
xianshiduihuakuang::xianshiduihuakuang(QWidget *parent, Qt::WFlags flags)
: QWidget(parent, flags)
{
ui.setupUi(this);
painUI();
}
xianshiduihuakuang::~xianshiduihuakuang()
{
}
void xianshiduihuakuang::mouseReleaseEvent(QMouseEvent*evt)
{
emit Clicked(this);
}
void xianshiduihuakuang::painUI()
{
QPushButton *button = new QPushButton(this);
button->setText("hello world");
button->move(200,200);
connect(button,SIGNAL(clicked()),this,SLOT(shdl()));
QLabel *label = new QLabel(this);
label->setText("hello wzg");
label->move(100,100);
connect(label,SIGNAL(clicked()),this,SLOT(shdl()));
}
void xianshiduihuakuang::shdl()
{
dialog = new QDialog;
dialog->show();
}