mainwindow.h#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QMouseEvent>namespace Ui {class MainWindow;}class MainWindow : public QMainWindow{ Q_OBJECTpublic: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void mouseMoveEvent(QEvent * event);private: Ui::MainWindow *ui;};#endif // MAINWINDOW_Hmain.cpp#include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; w.show(); return a.exec();}mainwindows.cpp#include "mainwindow.h"#include "ui_mainwindow.h"#include <QDebug>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); this->setMouseTracking(true); centralWidget()->setMouseTracking(true); }MainWindow::~MainWindow(){ delete ui;}void MainWindow::mouseMoveEvent(QEvent *event){ qDebug() << "1111111111111";}ui_mainvindow.h** Form generated from reading UI file 'mainwindow.ui'**** Created by: Qt User Interface Compiler version 5.2.1**** WARNING! All changes made in this file will be lost when recompiling UI file!********************************************************************************/#ifndef UI_MAINWINDOW_H#define UI_MAINWINDOW_H#include <QtCore/QVariant>#include <QtWidgets/QAction>#include <QtWidgets/QApplication>#include <QtWidgets/QButtonGroup>#include <QtWidgets/QHeaderView>#include <QtWidgets/QMainWindow>#include <QtWidgets/QMenuBar>#include <QtWidgets/QStatusBar>#include <QtWidgets/QToolBar>#include <QtWidgets/QWidget>QT_BEGIN_NAMESPACEclass Ui_MainWindow{public: QWidget *centralWidget; QMenuBar *menuBar; QToolBar *mainToolBar; QStatusBar *statusBar; void setupUi(QMainWindow *MainWindow) { if (MainWindow->objectName().isEmpty()) MainWindow->setObjectName(QStringLiteral("MainWindow")); MainWindow->resize(400, 300); MainWindow->setMouseTracking(true); centralWidget = new QWidget(MainWindow); centralWidget->setObjectName(QStringLiteral("centralWidget")); MainWindow->setCentralWidget(centralWidget); menuBar = new QMenuBar(MainWindow); menuBar->setObjectName(QStringLiteral("menuBar")); menuBar->setGeometry(QRect(0, 0, 400, 21)); MainWindow->setMenuBar(menuBar); mainToolBar = new QToolBar(MainWindow); mainToolBar->setObjectName(QStringLiteral("mainToolBar")); MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar); statusBar = new QStatusBar(MainWindow); statusBar->setObjectName(QStringLiteral("statusBar")); MainWindow->setStatusBar(statusBar); retranslateUi(MainWindow); QMetaObject::connectSlotsByName(MainWindow); } // setupUi void retranslateUi(QMainWindow *MainWindow) { MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0)); } // retranslateUi};namespace Ui { class MainWindow: public Ui_MainWindow {};} // namespace UiQT_END_NAMESPACE#endif // UI_MAINWINDOW_H
C++ (Qt)void MainWindow::mouseMoveEvent(QEvent *event){ qDebug() << "1111111111111"; QMainWindow::mouseMoveEvent(event);}
void MainWindow::mouseMoveEvent(QEvent *event){ qDebug() << "1111111111111"; QMouseEvent *MousEvent = static_cast<QMouseEvent*>(event); QMainWindow::mouseMoveEvent(MousEvent);}
C++ (Qt)centralWidget->setAttribute(Qt::WA_TransparentForMouseEvents);