To filter the mouse events in a QTextEdit, do I have to subclass it and implement a custom filter to the class?
I've been trying to add an event filter to a QTextEdit I have placed on the ui, but I can't filter mouse events. I get all other events, but input events(mouse and keyboard).
moveFilter = new MoveEventFilter(ui->textEdit);
ui->textEdit->setMouseTracking(true);
ui->textEdit->installEventFilter(moveFilter);
moveFilter = new MoveEventFilter(ui->textEdit);
ui->textEdit->setMouseTracking(true);
ui->textEdit->installEventFilter(moveFilter);
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() << obj->objectName();
}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(QTextEdit *parent){
//
canMove = false;
}
bool canMove;
private:
QPoint dragPosition;
protected:
bool eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseMove ){
qDebug() << obj->objectName();
}else{
qDebug() << obj->objectName() << event->type();
return QObject::eventFilter(obj, event);
}
}
};
#endif // MOVEEVENTFILTER_H
To copy to clipboard, switch view to plain text mode
Bookmarks