#include "mainwindow.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->centralwidget->setMouseTracking(true); setMouseTracking(true); } MainWindow::~MainWindow() { delete ui; } void MainWindow::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) ui->l1->setText("Left button press"); else ui->l1->setText("Right button press"); } void MainWindow::mouseReleaseEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) ui->l1->setText("Left button release"); else ui->l1->setText("Right button release"); } void MainWindow::mouseDoubleClickEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) ui->l1->setText("Left button double click"); else ui->l1->setText("Right button double click"); } void MainWindow::mouseMoveEvent(QMouseEvent *e) { QPoint pos = e->globalPos(); ui->l2->setText(QString("(%1,%2)").arg(pos.rx()).arg(pos.ry())); } void MainWindow::wheelEvent(QWheelEvent *e) { if (e->delta() > 0) ui->l1->setText("scroll up"); else ui->l1->setText("scroll down"); }