Results 1 to 2 of 2

Thread: disabled QwtPlotPanner is not immediately functional after being enabled

  1. #1
    Join Date
    Jun 2019
    Location
    France, Pau
    Posts
    60
    Thanks
    32
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default disabled QwtPlotPanner is not immediately functional after being enabled

    Hello,

    I disable QwtPlotPanner when I'm dealing with QGestureEvents in my MouseZoomer class (a QwtPlotMagnifier) because the panner is executing in priority (I can't pinch) and I enable the panner when the gesture is finished (Qt::GestureFinished).

    The panner is executing, IIRC, because Qt is generating mouse move events when pinching...

    My probelm is that after finishing the pinching gesture, the panner is not immediately functional : only, the mouse cursor is moving when I'm moving my finger over the canvas !

    I have to press elsewhere a second time to make the panner functionnal again !

    Is there something else I can do to make the panner functionnal again after finishing the pinch gesture ?

    I've already read the QwtPanner code and I didn't find what can be done to fix this issue. Should I manually post a mouse event after re-enabling the panner (and what kind of event) ? is it interesting to also grab gesture events in the panner and make this last do nothing between a pinch gesture ?

    Thank you for any tip !

    This is my MouseZoomer class (it zooms around mouse pointer and not the center of the canvas unlike the base class - and it handles both mouse wheel and pinch gestures) :

    Qt Code:
    1. class MouseZoomer : public QwtPlotMagnifier
    2. {
    3. typedef QwtPlotMagnifier Superclass;
    4. public:
    5. explicit MouseZoomer(QWidget* parent = nullptr);
    6.  
    7. void setPanner(QwtPlotPanner* const panner);
    8.  
    9. protected:
    10. bool eventFilter( QObject *, QEvent * ) override;
    11. void rescale(double factor) override;
    12. void widgetWheelEvent(QWheelEvent* evt) override;
    13.  
    14. protected:
    15. /* zoom around this position (mouse or pinch gesture)
    16.   * (translated into an axis value of course) */
    17. QPointF m_mouseOrPinchPos;
    18.  
    19. // panner need to be disabled while using the pinch gesture
    20. QPointer<QwtPlotPanner> m_panner;
    21.  
    22. //double m_wheelSteps;
    23. private:
    24. bool gestureEvent(QGestureEvent* event);
    25.  
    26. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. MouseZoomer::MouseZoomer(QWidget* parent /*= nullptr*/) :
    2. {
    3. // parent must be the QwtPlot's canvas widget
    4. parent->grabGesture(Qt::PinchGesture);
    5. }
    6.  
    7. void MouseZoomer::setPanner(QwtPlotPanner* const panner)
    8. {
    9. m_panner = panner;
    10. }
    11.  
    12. // overriden to handle pinch gesture on G1C devices
    13. bool MouseZoomer::eventFilter(QObject* obj, QEvent* event)
    14. {
    15. if (event->type() == QEvent::Gesture)
    16. {
    17. return gestureEvent(static_cast<QGestureEvent*>(event));
    18. }
    19.  
    20. // Make sure the rest of events are handled
    21. return Superclass::eventFilter(obj, event);
    22. }
    23.  
    24. bool MouseZoomer::gestureEvent(QGestureEvent* event)
    25. {
    26. if (QGesture* pinch = event->gesture(Qt::PinchGesture))
    27. {
    28. QPinchGesture* pinchGesture = static_cast<QPinchGesture*>(pinch);
    29.  
    30. if (m_panner && pinchGesture->state() == Qt::GestureStarted)
    31. {
    32. // panner need to be disabled when pinching starts
    33. m_panner->setEnabled(false);
    34. }
    35.  
    36. if (/*pinchGesture->state() == Qt::GestureUpdated &&*/
    37. pinchGesture->changeFlags() & QPinchGesture::ScaleFactorChanged)
    38. {
    39. // gesture positions are defined in screen coordinate and not in widget one (unlike mouse positions)
    40. const QPoint pos(pinchGesture->centerPoint().x(), pinchGesture->centerPoint().y());
    41. m_mouseOrPinchPos = canvas()->mapFromGlobal(pos);
    42.  
    43. rescale(pinchGesture->scaleFactor());
    44. }
    45.  
    46. // panner can be re-enabled after finishing the pinch gesture
    47. if (m_panner && pinchGesture->state() == Qt::GestureFinished)
    48. {
    49. m_panner->setEnabled(true);
    50. }
    51. }
    52.  
    53. return true;
    54. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by embeddedmz; 18th September 2019 at 14:15.

  2. #2
    Join Date
    Jun 2019
    Location
    France, Pau
    Posts
    60
    Thanks
    32
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: disabled QwtPlotPanner is not immediately functional after being enabled

    Fixed my issue by using another panner (which is also neat as it permits to replot while panning) : https://stackoverflow.com/questions/...tinuous-replot

Similar Threads

  1. QSocketNotifier enabled or disabled from another thread
    By johnsoga in forum Qt Programming
    Replies: 0
    Last Post: 26th September 2017, 20:33
  2. Replies: 1
    Last Post: 2nd May 2016, 17:14
  3. Mouse cursor on disabled/enabled widgets
    By luki222 in forum Qt Programming
    Replies: 0
    Last Post: 22nd February 2016, 22:31
  4. Replies: 6
    Last Post: 19th February 2014, 12:18
  5. Need to show a menu item with disabled look but functional
    By lalesculiviu in forum Qt Programming
    Replies: 4
    Last Post: 21st October 2009, 16:16

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.