Disabling Wheel Event in a QGraphicsView ?



  • Hi Qt community ,

    How to disable the wheel event in a QGraphicsView ?

    Sorry for the lazy post , and thanks for your comprehension ;)



  • As there is no property to enable or disable it you have to create a subclass and overwrite the implementation of the corresponding wheelEvent(). Something along the lines of:

    class MyGraphicsView : public QGraphicsView
    {
    	Q_OBJECT
    
    public:
    	explicit MyGraphicsView(QWidget* parent = nullptr) : QGraphicsView(parent) {}
    
    protected:
    	virtual void wheelEvent(QWheelEvent* event) Q_DECL_OVERRIDE {
    		event->accept();
    	}
    };
    


  • @Joel-Bodenmann

    Thanks for this unique answer .

    Actually , i figured out myself an another solution :

    void Scene::wheelEvent(QGraphicsSceneWheelEvent *event)
    {
        event->accept();
    }
    

    Probably not as good , so i'll use yours .

    topic->setAsSolved(true);


  • Moderators

    @Walux said:

    Probably not as good , so i'll use yours .

    just for clarification:
    Actually this is exactly the same approach, just a step later.
    (After the graphics view translated and forwarded it's received events to it's scene).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.