I just finished fixing this exact problem, so perhaps I can be of some help. What I did was create a new class with an event filter, and then installed that filter on the QGraphicsView from my .ui file.
It is important that you install the event filter on the viewport of the QGraphicsView, otherwise it won't work. Here is the code that I used, I can give more help if you find that you need it.
#ifndef EVENTFILTERIZER_H
#define EVENTFILTERIZER_H
#include <QObject>
#include <QEvent>
#include <QWheelEvent>
class EventFilterizer
: public QObject{
Q_OBJECT
public:
explicit EventFilterizer
(QObject *parent
= 0);
protected:
signals:
void scrollIntercept(int);
public slots:
};
#endif // EVENTFILTERIZER_H
#ifndef EVENTFILTERIZER_H
#define EVENTFILTERIZER_H
#include <QObject>
#include <QEvent>
#include <QWheelEvent>
class EventFilterizer : public QObject
{
Q_OBJECT
public:
explicit EventFilterizer(QObject *parent = 0);
protected:
bool eventFilter(QObject *obj, QEvent *event);
signals:
void scrollIntercept(int);
public slots:
};
#endif // EVENTFILTERIZER_H
To copy to clipboard, switch view to plain text mode
#include "eventfilterizer.h"
EventFilterizer
::EventFilterizer(QObject *parent
) :{
}
{
if (event
->type
() == QEvent::Wheel) {
//code to activate your zoom function, however you choose to do it
//I used a signal to activate mine
return true;
}
else
{
// standard event processing
return QObject::eventFilter(obj, event
);
}
}
#include "eventfilterizer.h"
EventFilterizer::EventFilterizer(QObject *parent) :
QObject(parent)
{
}
bool EventFilterizer::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::Wheel)
{
//code to activate your zoom function, however you choose to do it
//I used a signal to activate mine
return true;
}
else
{
// standard event processing
return QObject::eventFilter(obj, event);
}
}
To copy to clipboard, switch view to plain text mode
//this goes in the class that the graphicsview is a part of
EventFilterizer* interceptor = new EventFilterizer;
ui->gcodePlotter->viewport()->installEventFilter(interceptor);
//this goes in the class that the graphicsview is a part of
EventFilterizer* interceptor = new EventFilterizer;
ui->gcodePlotter->viewport()->installEventFilter(interceptor);
To copy to clipboard, switch view to plain text mode
Bookmarks