Results 1 to 3 of 3

Thread: Mouse double click on QwtScaleDraw

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Mouse double click on QwtScaleDraw

    hi friends/Experts,
    Im new to qwt programming. my task is to popup a dialog when user double click on the Axis of the qwt http://doc.qt.io/qt-4.8/QwtPlot
    I have overridden the QwtScaleDraw function to change the Axis properties of the Qwt graph plot.

    class CustomScaleDraw : public QwtScaleDraw

    and by using draw(), drawBackBone(),etc, I am changing the axis properties.

    My requirement is to popup a dialog to change the properties of the Axis when the user double clicks on the axis of the graph.

    As QWtScaleDraw is not inherited with QObject, neither mouseDoubleClick nor eventFilter function is able to capture the mouse double click on the Axis. How can I do that?

    Please help me
    Thanks
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Mouse double click on QwtScaleDraw

    Hi,

    I have a PlotAxisPicker, maybe that help:

    Header:

    Qt Code:
    1. #ifndef PLOTAXISPICKER_H
    2. #define PLOTAXISPICKER_H
    3.  
    4. // Qt
    5. #include <QObject>
    6. #include <QDebug>
    7. #include <QEvent>
    8. #include <QResizeEvent>
    9. #include <QMouseEvent>
    10. #include <QFrame>
    11.  
    12. // Qwt
    13. #include "qwt_plot.h"
    14. #include "qwt_scale_widget.h"
    15.  
    16. class PlotAxisPicker : public QObject
    17. {
    18. Q_OBJECT
    19. public:
    20. explicit PlotAxisPicker( QwtPlot::Axis axisId, QwtPlot *plot = nullptr );
    21.  
    22. signals:
    23. void doubleClickedLeft();
    24.  
    25. public slots:
    26.  
    27. private:
    28. QwtScaleWidget *pScaleWidget;
    29. bool eventFilter(QObject *, QEvent *event);
    30. };
    31.  
    32. #endif // PLOTAXISPICKER_H
    To copy to clipboard, switch view to plain text mode 

    CPP:

    Qt Code:
    1. #include "plotaxispicker.h"
    2.  
    3. // Qt
    4. #include <QDebug>
    5. #include <QEvent>
    6. #include <QMouseEvent>
    7.  
    8. // Qwt
    9. #include "qwt_plot.h"
    10. #include "qwt_scale_widget.h"
    11.  
    12. PlotAxisPicker::PlotAxisPicker( QwtPlot::Axis axisId, QwtPlot *plot) : QObject(plot)
    13. {
    14. pScaleWidget = plot->axisWidget( axisId );
    15. pScaleWidget->setMouseTracking( true );
    16. pScaleWidget->setFocusPolicy( Qt::NoFocus );
    17. if ( pScaleWidget )
    18. pScaleWidget->installEventFilter( this );
    19.  
    20. }
    21.  
    22. bool PlotAxisPicker::eventFilter(QObject *object, QEvent *event)
    23. {
    24.  
    25. if (object != (QObject *)pScaleWidget )
    26. {
    27. return false;
    28. }
    29.  
    30. if ( object==(QObject *)pScaleWidget )
    31. {
    32.  
    33. const QMouseEvent *mouseEvent = (const QMouseEvent *)event;
    34.  
    35. switch ( event->type() )
    36. {
    37. case QEvent::MouseButtonDblClick:
    38. {
    39. if( mouseEvent->button()==Qt::LeftButton)
    40. {
    41. qDebug() << Q_FUNC_INFO << mouseEvent;
    42. emit doubleClickedLeft();
    43. }
    44. break;
    45. }
    46. default:;
    47. }
    48. }
    49.  
    50. return QObject::eventFilter(object, event);
    51. }
    To copy to clipboard, switch view to plain text mode 

    In my subclass Plot (from QwtPlot)

    Qt Code:
    1. pAxisXPicker = new PlotAxisPicker(QwtPlot::xBottom, this);
    2. pAxisYPicker = new PlotAxisPicker(QwtPlot::yLeft, this);
    To copy to clipboard, switch view to plain text mode 

    This is a workaround, because i need a double click on the axis title, but the axis title is not a QwtText Widget like the plot title or plot footer.
    Guess the same problem like you, but you need the scaledraw and i'm not.
    Last edited by HappyCoder; 11th April 2016 at 17:04.

  3. The following user says thank you to HappyCoder for this useful post:

    wagmare (12th April 2016)

  4. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouse double click on QwtScaleDraw

    In general the provided idea is the right one - there are widgets ( QwtPlot::axisWidget() ), representing the scales, that can receives events.

    Uwe

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

    wagmare (12th April 2016)

Similar Threads

  1. Replies: 2
    Last Post: 16th July 2012, 13:40
  2. Replies: 2
    Last Post: 5th March 2012, 12:09
  3. Replies: 1
    Last Post: 31st October 2011, 00:50
  4. can not get mouse double click event for QGraphicsItem
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 14th September 2009, 21:36
  5. Replies: 1
    Last Post: 9th February 2007, 10:41

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.