2-3-4
This commit is contained in:
parent
5595711307
commit
ee2bce6697
3 changed files with 45 additions and 16 deletions
|
@ -2,14 +2,39 @@
|
|||
#include "ui_mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
ui->setupUi(this);
|
||||
ui->centralwidget->setMouseTracking(true);
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QWheelEvent>
|
||||
#include <QMouseEvent>
|
||||
#include <QWheelEvent>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
|
@ -22,6 +22,10 @@ private:
|
|||
Ui::MainWindow *ui;
|
||||
|
||||
protected:
|
||||
void mouseEvent(QMouseEvent *e);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
void mouseDoubleClickEvent(QMouseEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void wheelEvent(QWheelEvent *e);
|
||||
};
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -14,12 +14,12 @@
|
|||
<string>4490</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QLabel" name="l2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<x>450</x>
|
||||
<y>160</y>
|
||||
<width>77</width>
|
||||
<width>311</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -27,12 +27,12 @@
|
|||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="l1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>330</x>
|
||||
<x>160</x>
|
||||
<y>160</y>
|
||||
<width>77</width>
|
||||
<width>221</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
|
Reference in a new issue