This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/SoftwareDesign/Code/2-3-4/mainwindow.cpp

41 lines
1.1 KiB
C++
Raw Normal View History

2022-03-29 15:03:33 +00:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
2022-04-19 07:19:23 +00:00
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
ui->centralwidget->setMouseTracking(true);
setMouseTracking(true);
2022-03-29 15:03:33 +00:00
}
2022-04-19 07:19:23 +00:00
MainWindow::~MainWindow() { delete ui; }
2022-03-29 15:03:33 +00:00
2022-04-19 07:19:23 +00:00
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");
}