#include "mainwindow.h" #include #include #include class EventLabel : public QLabel { protected: void mouseMoveEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); }; void EventLabel::mouseMoveEvent(QMouseEvent *event){ this->setText(QString("

Move: (%1, %2)

").arg(QString::number(event->x()),QString::number(event->y))); } void EventLabel::mousePressEvent(QMouseEvent *event){ this->setText(QString("

Press: (%1, %2)

").arg(QString::number(event->x()),QString::number(event->y))); } void EventLabel::mouseReleaseEvent(QMouseEvent *event){ QString msg; msg.sprintf("

Release: (%d, %d)

", event->x(), event->y()); } int main(int argc, char *argv[]) { QApplication a(argc, argv); EventLabel *label = new EventLabel; label->setWindowTitle("MouseEvent Demo"); label->resize(300,200); label->show(); return a.exec(); }