2023-08-09 18:22:00 +08:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
2023-08-13 11:47:17 +08:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
|
|
|
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("<center><h1>Move: (%1, %2)</h1></center>").arg(QString::number(event->x()),QString::number(event->y)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventLabel::mousePressEvent(QMouseEvent *event){
|
|
|
|
this->setText(QString("<center><h1>Press: (%1, %2)</h1></center>").arg(QString::number(event->x()),QString::number(event->y)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventLabel::mouseReleaseEvent(QMouseEvent *event){
|
|
|
|
QString msg;
|
|
|
|
msg.sprintf("<center><h1>Release: (%d, %d)</h1></center>", event->x(), event->y());
|
|
|
|
}
|
2023-08-09 18:22:00 +08:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QApplication a(argc, argv);
|
2023-08-13 11:47:17 +08:00
|
|
|
|
|
|
|
EventLabel *label = new EventLabel;
|
|
|
|
label->setWindowTitle("MouseEvent Demo");
|
|
|
|
label->resize(300,200);
|
|
|
|
label->show();
|
|
|
|
|
2023-08-09 18:22:00 +08:00
|
|
|
return a.exec();
|
|
|
|
}
|