Search code examples
c++user-interfaceplotqwt

QwtPicker: disable movement of cursor via arrow keys


According to the Qwt documentation of QwtPicker (which is a superclas of QwtPlotZoomer, the class I'm using) the cursor can be moved using the arrow keys:

The cursor can be moved using the arrow keys

However, I wan't to disable this, as the arrow keys have different purposes in my application.

Is this possible via the API? Otherwise I need to subclass my QwtPlotZoomer..


Solution

  • Ok, just ended up overriding the relevant functions of QwtPicker, this works fine.

    class MyQwtPlotZoomer : public QwtPlotZoomer
    {
        public:
            MyQwtPlotZoomer(int xAxis, int yAxis,  QwtPlotCanvas* canvas, bool doReplot = true) : QwtPlotZoomer(xAxis, yAxis, canvas, doReplot){ }
    
            virtual ~MyQwtPlotZoomer(){ }
    
        protected:
            virtual void widgetKeyPressEvent(QKeyEvent* ke)
            {
                if ( !isActive() )
                {
                    if ( keyMatch( KeyUndo, ke ) )
                        zoom( -1 );
                    else if ( keyMatch( KeyRedo, ke ) )
                        zoom( +1 );
                    else if ( keyMatch( KeyHome, ke ) )
                        zoom( 0 );
                }
            }
    
            virtual void widgetKeyReleaseEvent(QKeyEvent*){ }
    };