Results 1 to 5 of 5

Thread: Can QwtPlotPicker emit the selected signal for more than one mouse event?

  1. #1
    Join Date
    Jul 2009
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Can QwtPlotPicker emit the selected signal for more than one mouse event?

    Hi,

    I am trying to create a QwtPlotPicker class that can select left and right boundary points on my QwtPlot. My original idea was to have the left mouse button select the left boundary and the right mouse button to select the right. However, when trying to implement this, I've noticed that I can only get the selected( QwtDoublePoint point ) SIGNAL function to work with only a left mouse button click. Even a CTRL+left mouse button does not emit the signal. Is it possible to have multiple button events emit the selected SIGNAL, or is it only active for QwtEventPatter::MouseSelect1? If it's the latter, I guess I would need to have independent pickers for both the left and the right boundaries?

    I am running Qwt 5.2.0.

    Here is my code:
    Qt Code:
    1. signalPicker = new PlotPicker( canvas() );
    2. signalPicker->setSelectionFlags( QwtPicker::PointSelection | QwtPicker::ClickSelection );
    3. signalPicker->setRubberBandPen( QColor( Qt::gray ) );
    4. signalPicker->setMousePattern( QwtEventPattern::MouseSelect1, Qt::LeftButton );
    5. signalPicker->setMousePattern( QwtEventPattern::MouseSelect2, Qt::LeftButton, Qt::ControlModifier );
    6. signalPicker->setMousePattern( QwtEventPattern::MouseSelect3, Qt::RightButton );
    7. signalPicker->setMousePattern( QwtEventPattern::MouseSelect4, Qt::RightButton, Qt::ControlModifier );
    8. signalPicker->setEnabled( false );
    9. connect( signalPicker, SIGNAL( selected( QwtDoublePoint) ), this, SLOT( setSelectedPoint( QwtDoublePoint ) ) );
    10. connect( signalPicker, SIGNAL( setLeft() ), this, SLOT( setSignalLeft() ) );
    11. connect( signalPicker, SIGNAL( setRight() ), this, SLOT( setSignalRight() ) );
    12. connect( signalPicker, SIGNAL( clearLeft() ), this, SLOT( resetSignalLeft() ) );
    13. connect( signalPicker, SIGNAL( clearRight() ), this, SLOT( resetSignalRight() ) );
    To copy to clipboard, switch view to plain text mode 

    Thanks for your time.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can QwtPlotPicker emit the selected signal for more than one mouse event?

    Look at the source code for QwtPlotPicker and QwtPickerClickPointMachine. I think you'll see that the only time selected() is emitted is for a left click. It doesn't matter what you set the other event patterns to, only MouseSelect1 will result in a selected() signal.

    So, since Qwt 5.2 doesn't let you change the picker machine (setStatemachine() is private in QwtPicker), you have to do some tricks: Look at the transition() methods in the QwtPicker and the QwtPickerClickPointMachine. Derive your own QwtPickerMachine class to do what you want (basically, use both left and right clicks to construct the same command list). Write your own QwtPlotPicker class and create an instance of your own picker machine as a member variable. Override the QwtPlotPicker::transition() method to call your machine instead of the default machine, but do everything else the same way.

    I think that in 6.0, the setStateMachine() method is exposed, so you probably won't have to derive your own plot picker class but will only have to make the customized state machine.

    It would probably help your app if you also changed the picker's transition() class to emit different signals on left and right click instead of just the single selected() event, because otherwise how will you tell which button was clicked?

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

    Default Re: Can QwtPlotPicker emit the selected signal for more than one mouse event?

    What about using using different pickers - one for each type of mouse click you want to have ?

    Uwe

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can QwtPlotPicker emit the selected signal for more than one mouse event?

    Good idea - I didn't realize that two pickers could be active at the same time. If they are both enabled, do they each get all of the mouse events?

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

    Default Re: Can QwtPlotPicker emit the selected signal for more than one mouse event?

    All of these helper classes for navigating/selecting on the plot canvas install an event filter ( QObject::installEventFilter), where they handle certain events posted to the canvas. As long as an event filter doesn't return true ( what the Qwt classes don't do ) the event is processed by all other installed event filters and in the end by the canvas itself.

    Uwe

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

    d_stranz (6th February 2011)

Similar Threads

  1. Replies: 2
    Last Post: 1st January 2011, 17:00
  2. Replies: 2
    Last Post: 1st January 2011, 00:16
  3. How to emit mouse press event in QPushButton
    By dpatel in forum Qt Programming
    Replies: 1
    Last Post: 30th December 2010, 13:00
  4. Replies: 3
    Last Post: 6th October 2010, 08:33
  5. Is there an event or emit with QDockWidget?
    By bitChanger in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 01:46

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.