I get no errors whatsoever. It just seems that the filter can't get the mouse events.
I did a new project, but the results are the same:
widget.cpp:
#include "widget.h"
#include "ui_widget.h"
ui(new Ui::Widget)
{
ui->setupUi(this);
moveFilter = new MoveEventFilter(this);
ui->textEdit->setMouseTracking(true);
ui->textEdit->installEventFilter(moveFilter);
setMouseTracking(true);
installEventFilter(moveFilter);
}
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
moveFilter = new MoveEventFilter(this);
ui->textEdit->setMouseTracking(true);
ui->textEdit->installEventFilter(moveFilter);
setMouseTracking(true);
installEventFilter(moveFilter);
}
To copy to clipboard, switch view to plain text mode
widget.h:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include "moveEventFilter.h"
namespace Ui {
class Widget;
}
Q_OBJECT
public:
~Widget();
protected:
private:
Ui::Widget *ui;
MoveEventFilter *moveFilter;
};
#endif // WIDGET_H
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include "moveEventFilter.h"
namespace Ui {
class Widget;
}
class Widget : public QWidget {
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
protected:
void changeEvent(QEvent *e);
private:
Ui::Widget *ui;
MoveEventFilter *moveFilter;
};
#endif // WIDGET_H
To copy to clipboard, switch view to plain text mode
moveEventFilter.h:
#ifndef MOVEEVENTFILTER_H
#define MOVEEVENTFILTER_H
#include <QtGui>
#include <QDebug>
class MoveEventFilter
: public QObject{
Q_OBJECT
public:
//
canMove = false;
}
bool canMove;
private:
protected:
{
if (event
->type
() == QEvent::MouseMove ){ qDebug() << "1111111111111";
return true;
}else{
qDebug() << obj->objectName() << event->type();
return QObject::eventFilter(obj, event
);
}
}
};
#endif // MOVEEVENTFILTER_H
#ifndef MOVEEVENTFILTER_H
#define MOVEEVENTFILTER_H
#include <QtGui>
#include <QDebug>
class MoveEventFilter : public QObject
{
Q_OBJECT
public:
MoveEventFilter(QWidget *parent){
//
canMove = false;
}
bool canMove;
private:
QPoint dragPosition;
protected:
bool eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseMove ){
qDebug() << "1111111111111";
return true;
}else{
qDebug() << obj->objectName() << event->type();
return QObject::eventFilter(obj, event);
}
}
};
#endif // MOVEEVENTFILTER_H
To copy to clipboard, switch view to plain text mode
With that code I only filter mouse moves when directly on the widget, but not on the textEdit.
Bookmarks