Results 1 to 6 of 6

Thread: QwtPlotMagnifier widgetKeyPressEvent

  1. #1
    Join Date
    Nov 2007
    Posts
    26
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QwtPlotMagnifier widgetKeyPressEvent

    Do I need to do something to enable QwtPlotMagnifier::widgetKeyPressEvent to work?

    Im trying to zoom in with the mouse wheel in only x or y if the x or y key is pressed. Nothing happens with the code below, otherwise the QwtPlotMagnifier seems to working well.


    Qt Code:
    1. class Zoom: public QwtPlotMagnifier
    2. {
    3. public:
    4. Zoom(QwtPlotCanvas *canvas): QwtPlotMagnifier(canvas)
    5. {
    6. }
    7.  
    8. virtual void Zoom::widgetKeyPressEvent (QKeyEvent *ke)
    9. {
    10. if (ke->key() == Qt::Key_X)
    11. {
    12. QwtPlotMagnifier::setAxisEnabled(QwtPlot::yLeft, false);
    13. }
    14. else if (ke->key() == Qt::Key_Y)
    15. {
    16. QwtPlotMagnifier::setAxisEnabled(QwtPlot::xBottom, false);
    17. }
    18. }
    19. virtual void Zoom::widgetKeyReleaseEvent(QKeyEvent *ke)
    20. {
    21. if (ke->key() == Qt::Key_X)
    22. {
    23. QwtPlotMagnifier::setAxisEnabled(QwtPlot::yLeft, true);
    24. }
    25. else if (ke->key() == Qt::Key_Y)
    26. {
    27. QwtPlotMagnifier::setAxisEnabled(QwtPlot::xBottom, true);
    28. }
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by robertson1; 4th June 2010 at 01:09. Reason: code formatting

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,253
    Thanked 860 Times in 809 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotMagnifier widgetKeyPressEvent

    You have to call the methods of the base class at the end of your implementations of widgetKeyPressEvent/widgetKeyReleaseEvent.

    Uwe

  3. #3
    Join Date
    Nov 2007
    Posts
    26
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotMagnifier widgetKeyPressEvent

    I have tried this without sucess:

    Qt Code:
    1. virtual void Zoom::widgetKeyPressEvent (QKeyEvent *ke)
    2. {
    3. if (ke->key() == Qt::Key_X)
    4. {
    5. QwtPlotMagnifier::setAxisEnabled(QwtPlot::yLeft, false);
    6. }
    7. else if (ke->key() == Qt::Key_Y)
    8. {
    9. QwtPlotMagnifier::setAxisEnabled(QwtPlot::xBottom, false);
    10. }
    11. QwtMagnifier::widgetKeyPressEvent(ke);
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by robertson1; 4th June 2010 at 15:48.

  4. #4
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwtPlotMagnifier widgetKeyPressEvent

    Try using the following code for your constructor:
    Qt Code:
    1. Zoom(QwtPlotCanvas *canvas): QwtPlotMagnifier(canvas)
    2. {
    3. setMouseButtonState(Qt::KeypadModifier);
    4. }
    To copy to clipboard, switch view to plain text mode 
    The issue is that after you press the x or y keys, the QwtPlotMagnifier class will ignore the wheel event if a key is being held. By setting this Qt::KeypadModifier or any other Qt::KeyboardModifiers, you can specify what key must be pressed while using the mouse wheel to zoom. This should fix the issue.

  5. #5
    Join Date
    Nov 2007
    Posts
    26
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotMagnifier widgetKeyPressEvent

    The wheel events are workiing ok, my problem is I cant seem to get my re-implementation of widgetKeyPressEvent to work. It's never getting triggered when I press a key.

  6. #6
    Join Date
    Nov 2007
    Posts
    26
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlotMagnifier widgetKeyPressEvent

    Nevermind I can get the result I wanted by just using my parent widgets keyPressEvent instead.

    Thanks for the suggestions though,

Similar Threads

  1. QwtPlotMagnifier initial zoom
    By jomarin in forum Qwt
    Replies: 6
    Last Post: 6th May 2010, 09:29
  2. Map QwtPlotMagnifier to a button
    By volatile_ah in forum Qwt
    Replies: 1
    Last Post: 28th January 2010, 10:51
  3. Replies: 3
    Last Post: 25th August 2009, 23:35
  4. Replies: 1
    Last Post: 5th March 2009, 06:52
  5. Problem with the QwtPlotMagnifier
    By seguprasad in forum Qwt
    Replies: 8
    Last Post: 6th December 2007, 12:11

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.