void wheelEvent ( QWheelEvent * event ) { event->ignore();}
#include "GraphicsLegend.h"#include <QGraphicsScene>#include <QGraphicsView>#include <QGraphicsTextItem>class GraphicsScene : public QGraphicsScene{public: GraphicsScene(); QGraphicsView *getView() { return &view; }private: QGraphicsView view; GraphicsLegend legend; void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);};
#include "GraphicsScene.h"GraphicsScene::GraphicsScene(): legend (&view){ view.setScene(this); QGraphicsTextItem *text = this->addText("text"); text->setPos(200,200);}void GraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *){ exit(1);}
#include <QWidget>#include <QPainter>#include <QMouseEvent>class GraphicsLegend : public QWidget{ Q_OBJECTpublic: GraphicsLegend(QWidget* parent);protected: void paintEvent(QPaintEvent* ev); bool eventFilter(QObject *obj, QEvent *ev); virtual void mousePressEvent ( QMouseEvent * event ) { event->ignore(); } void wheelEvent ( QWheelEvent * event ) { event->ignore(); }};
GraphicsLegend *legend = new GraphicsLegend(&view);
GraphicsLegend(QWidget* parent){ resize(parent->size()); parent->installEventFilter(this); }
class GraphicsLegend : public QWidget{ Q_OBJECTpublic: GraphicsLegend(QWidget* parent) : QWidget (parent) { resize(parent->size()); parent->installEventFilter(this); }protected: void paintEvent(QPaintEvent* ev) { QPainter painter(this); painter.drawText(50, 50, "!!"); } bool eventFilter(QObject *obj, QEvent *ev) { if(obj==parentWidget() && ev->type()==QEvent::Resize) resize(parentWidget()->size()); return false; }};
#include <QGraphicsView>#include <QEvent>class GraphicsView : public QGraphicsView{public: GraphicsView();protected: virtual bool event(QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { this->mousePressEvent((QMouseEvent *)event); return false; } else if ( event->type() == QEvent::Wheel ) { this->wheelEvent((QWheelEvent *)event); return false; } // else if ... и т.д. return QGraphicsView::event(event); }};