Problem got my attention so I quickly implemented a test app.
#ifndef FILTER_H
#define FILTER_H
#include <QtCore>
#include <QtGui>
#include <QDebug>
#include <QtScript>
class MoveEventFilter
: public QObject{ Q_OBJECT
public:
canMove = false;
}
bool canMove;
protected:
{
qDebug() << obj->objectName() << mo.enumerator(mo.indexOfEnumerator("Type")).valueToKey(event->type());
if (event
->type
() == QEvent::MouseMove ){ qDebug
() <<
QString("(%1|%2)").
arg(me
->pos
().
x()).
arg(me
->pos
().
y());
return true;
}
return QObject::eventFilter(obj, event
);
}
};
class MouseTrack
: public QLabel{ Q_OBJECT
public:
}
};
#endif // FILTER_H
#ifndef FILTER_H
#define FILTER_H
#include <QtCore>
#include <QtGui>
#include <QDebug>
#include <QtScript>
class MoveEventFilter : public QObject
{ Q_OBJECT
public:
MoveEventFilter(QWidget* parent = 0) : QObject(parent) {
canMove = false;
}
bool canMove;
protected:
bool eventFilter(QObject *obj, QEvent *event)
{
QMetaObject mo = QEvent::staticMetaObject;
qDebug() << obj->objectName() << mo.enumerator(mo.indexOfEnumerator("Type")).valueToKey(event->type());
if (event->type() == QEvent::MouseMove ){
QMouseEvent* me = static_cast<QMouseEvent*>(event);
qDebug() << QString("(%1|%2)").arg(me->pos().x()).arg(me->pos().y());
return true;
}
return QObject::eventFilter(obj, event);
}
};
class MouseTrack : public QLabel
{ Q_OBJECT
public:
MouseTrack(QWidget* parent = 0) : QLabel(parent) {
}
};
#endif // FILTER_H
To copy to clipboard, switch view to plain text mode
#include <QtCore>
#include <QtGui>
#include "filter.h"
int main(int argc, char *argv[])
{
te->setObjectName("textedit");
MouseTrack* mt = new MouseTrack();
mt->setMinimumHeight(100);
mt->setObjectName("MouseTrack");
MoveEventFilter* filter = new MoveEventFilter();
te->setMouseTracking(true);
te->installEventFilter(filter);
mt->setMouseTracking(true);
mt->installEventFilter(filter);
vl->addWidget(te,0);
vl->addWidget(mt,1);
w.setLayout(vl);
w.show();
QObject::connect(&a,
SIGNAL(lastWindowClosed
()),
&a,
SLOT(quit
()));
return a.exec();
}
#include <QtCore>
#include <QtGui>
#include "filter.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget w;
QTextEdit* te = new QTextEdit();
te->setObjectName("textedit");
MouseTrack* mt = new MouseTrack();
mt->setMinimumHeight(100);
mt->setObjectName("MouseTrack");
MoveEventFilter* filter = new MoveEventFilter();
te->setMouseTracking(true);
te->installEventFilter(filter);
mt->setMouseTracking(true);
mt->installEventFilter(filter);
QVBoxLayout* vl = new QVBoxLayout();
vl->addWidget(te,0);
vl->addWidget(mt,1);
w.setLayout(vl);
w.show();
QObject::connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
To copy to clipboard, switch view to plain text mode
If you play around with it a bit, you see that, that MouseMoves are filtered on the textedit, but only on the border!!
I guess the main text edit is some subwidget?
Joh
PS: I took the time and figured out how to convert those QEvent::type codes into readable names.
QEvent::staticMetaObject.
enumerator(QEvent::staticMetaObject.
indexOfEnumerator("Type")).
valueToKey(event
->type
());
QEvent::staticMetaObject.enumerator(QEvent::staticMetaObject.indexOfEnumerator("Type")).valueToKey(event->type());
To copy to clipboard, switch view to plain text mode
Bookmarks