Results 1 to 6 of 6

Thread: Change mouse bindings for qwtplotzoomer

  1. #1
    Join Date
    Jul 2008
    Location
    Norway, Trondheim
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Change mouse bindings for qwtplotzoomer

    Hi

    I`m creating a plot widget based on QwtPlot that has three buttons to toggle zoom-in, zoom-out, and panning/draggin (like in matlab). How can I change the mouse bindings? I have slots that are called when the different buttons are toggled. I want to set the left mouse-button to handle everything depending on which button is toggled: zoom in when zoom-in is toggled, zoom out when zoom-out is toggled, and pan/drag the plot when the pan-button is toggled. So far I`ve tried
    setMousePattern(QwtEventPattern::MouseSelect3,Qt:: LeftButton); // when pan is toggled

    setMousePattern(QwtEventPattern::MouseSelect2,Qt:: LeftButton); // when zoom-out is toggled


    setMousePattern(QwtEventPattern::MouseSelect1,Qt:: LeftButton); // when zoom-in is toggled

    but it doesn`t give me the right behaviour. I don`t want to zoom-out using right-clicks as that button is used for conext-menu. And not all mouses have a mid-button for panning...

    -Ivar

  2. #2
    Join Date
    Jul 2008
    Location
    Norway, Trondheim
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change mouse bindings for qwtplotzoomer

    Solved it....

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    3,896
    Thanks
    225
    Thanked 607 Times in 597 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Change mouse bindings for qwtplotzoomer

    Quote Originally Posted by ivareske View Post
    Solved it....
    Nice. Don't bother to show how, because that might help someone else with a similar problem. After all, this forum exists only to answer your questions, not to help the community as a whole.

  4. #4
    Join Date
    Jul 2008
    Location
    Norway, Trondheim
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change mouse bindings for qwtplotzoomer

    Really...? I thought this forum only existed to solve my problems...

    --------------------------------------------------------Zoomer.h
    #ifndef ZOOMER_H
    #define ZOOMER_H

    #include <qwt_plot_zoomer.h>


    class Zoomer: public QwtPlotZoomer{

    public:
    enum zoomMode{In, Out};
    Zoomer(int xAxis, int yAxis, QwtPlotCanvas *canvas);
    bool zoomModeEnabled( Zoomer::zoomMode mode ) const;
    void enableZoomMode( Zoomer::zoomMode mode, bool enabled );
    private:
    bool zoomIn_;
    bool zoomOut_;
    };


    #endif


    -----------------------------------------------Zoomer.cpp
    #include "Zoomer.h"




    Zoomer::Zoomer(int xAxis, int yAxis, QwtPlotCanvas *canvas) : QwtPlotZoomer(xAxis, yAxis, canvas){

    setSelectionFlags(QwtPicker:ragSelection | QwtPicker::CornerToCorner);
    setTrackerMode(QwtPicker::AlwaysOff);
    setRubberBand(QwtPicker::NoRubberBand);

    // RightButton: zoom out by 1
    // Ctrl+RightButton: zoom out to full size

    //setMousePattern(QwtEventPattern::MouseSelect2,Qt:: RightButton, Qt::ControlModifier);
    //setMousePattern(QwtEventPattern::MouseSelect3,Qt:: RightButton);

    //setMousePattern(QwtEventPattern::MouseSelect2,Qt:: NoButton, Qt::ControlModifier);
    //setMousePattern(QwtEventPattern::MouseSelect3,Qt:: NoButton);

    setMousePattern(QwtEventPattern::MouseSelect1,Qt:: NoButton);
    setMousePattern(QwtEventPattern::MouseSelect2,Qt:: NoButton);
    setMousePattern(QwtEventPattern::MouseSelect3,Qt:: NoButton);
    setMousePattern(QwtEventPattern::MouseSelect4,Qt:: NoButton);
    setMousePattern(QwtEventPattern::MouseSelect5,Qt:: NoButton);
    setMousePattern(QwtEventPattern::MouseSelect6,Qt:: NoButton);

    zoomIn_ = false;
    zoomOut_ = false;

    }

    void Zoomer::enableZoomMode( Zoomer::zoomMode mode, bool enabled ){
    if( mode==Zoomer::In ){
    zoomIn_ = enabled;
    zoomOut_ = false;
    setMousePattern(QwtEventPattern::MouseSelect3,Qt:: NoButton);
    if( enabled ){
    setMousePattern(QwtEventPattern::MouseSelect1,Qt:: LeftButton);
    }else{
    setMousePattern(QwtEventPattern::MouseSelect1,Qt:: NoButton);
    }
    }
    if( mode==Zoomer::Out ){
    zoomIn_ = false;
    setMousePattern(QwtEventPattern::MouseSelect1,Qt:: NoButton);
    zoomOut_ = enabled;
    if( enabled ){
    setMousePattern(QwtEventPattern::MouseSelect3,Qt:: LeftButton);
    }else{
    setMousePattern(QwtEventPattern::MouseSelect3,Qt:: NoButton);
    }
    }

    }

    bool Zoomer::zoomModeEnabled( Zoomer::zoomMode mode ) const{
    if( mode==Zoomer::In ){
    return zoomIn_;
    }else{
    return zoomOut_;
    }

    }

  5. The following user says thank you to ivareske for this useful post:

    corrado1972 (23rd March 2011)

  6. #5
    Join Date
    Sep 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Change mouse bindings for qwtplotzoomer

    Please, don't argue. This code snippets help me a lot.

  7. #6
    Join Date
    Jun 2015
    Posts
    51
    Thanks
    10
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change mouse bindings for qwtplotzoomer

    Hi ivareske,

    Can you help me in below regards,
    How did you add button to toggle QwtPlotZoomer on legend ?

    Please reply, I'm stuck in this

    Thanks

Similar Threads

  1. Replies: 3
    Last Post: 10th October 2011, 17:55
  2. Replies: 2
    Last Post: 1st January 2011, 18:00
  3. Replies: 1
    Last Post: 16th July 2009, 17:58
  4. Replies: 1
    Last Post: 10th July 2009, 10:54
  5. Replies: 3
    Last Post: 4th December 2007, 11:04

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.