Results 1 to 5 of 5

Thread: QwtPlotPanner/QwtPlotZoomer issue when the plot loses the focus

  1. #1
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QwtPlotPanner/QwtPlotZoomer issue when the plot loses the focus

    QwtPanner: while it is active (isVisible() == true), it must handle FocusOut event to ends up panning. Consider context menu invokation with ContextMenu key while panning - context menu grabs the focus and subsequent mouse release event (if user picks some item from the menu), so when returning back to the plot's canvas widget there will be inconsistent state due to the panner thinks it still active, while there is no longer mouse button held. We also may have Qt::ClosedHandCursor indicating panning (if we applied QwtPanner::setCursor(Qt::ClosedHandCursor)), but we no longer have actual panning (no MouseMove events occur due to no mouse button held).

    I think the same is applicable to QwtPlotZoomer.

    QwtPanner: while it activates at certain mouse button press and certain keyboard modifiers (QwtPanner::setMouseButton()), it ends at any mouse button release and any keyboard modifiers. IMHO, for sake of simmetry (and simplicity) ending combination must be the same as beginning.

  2. #2
    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: QwtPlotPanner/QwtPlotZoomer issue when the plot loses the focus

    Focus events are for the keyboard - not the mouse. When setting a Qt::NoFocus policy to the canvas it will never have the focus - even when using the mouse on it.
    Guess what you are thinking of is what is propagated as QEvent::UngrabMouse for QQuickItem/QGraphicsItem.

    Uwe

  3. #3
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QwtPlotPanner/QwtPlotZoomer issue when the plot loses the focus

    Hi, Uwe. Thanks for the responce.

    Yes, Qt::NoFocus is an option for the plot canvas. But it has no meaning. Key moment - panner ends up at mouse release event in assumption that mouse was held all the time, but context menu steals mouse release event, mouse is no longer held (and panner will no longer receive MouseMove events as it expects), but the panner don't know about things happen. It's still active (isVisible()==true), but no longer works. A visible artefact - panner still shows override cursor (e.g. Qt::ClosedHandCursor).

    My initial question was a narrow question in assumption that plot canvas is focus-aware. I was not about QEvent::UngrabMouse for QQuickItem/QGraphicsItem.

  4. #4
    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: QwtPlotPanner/QwtPlotZoomer issue when the plot loses the focus

    I was not about QEvent::UngrabMouse for QQuickItem/QGraphicsItem.
    I had a quick look at the implementation of QWidget::grabMouse + releaseMouse and it looks like the current mouse grabber is stored in global variable qt_mouseGrb. You have access to it using QWidget::mouseGrabber, but there seems to be no indication from Qt about when the value of the mouseGrabber is changing ( this is what the UngrabMouse event is about for the other systems ).

    So maybe what can be done is to do "QWidget::mouseGrabber() == this" checks in the plot canvas to identify a loss of being the mouse grabber without having a proper mouse release event. Not 100% sure what type events would be those where this check has to be performed.

    Uwe

  5. #5
    Join Date
    Jun 2014
    Posts
    17
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QwtPlotPanner/QwtPlotZoomer issue when the plot loses the focus

    Thanks for advice.

    Currently, I just handle FocusOut event in the eventFilter of plot's canvas widget. It's sufficient for my particular case right now. The code something like this (the code applies panning and ends up it correctly, and cancels zooming and ends up it correctly):
    Qt Code:
    1. ...
    2. else if (QEvent::FocusOut == event->type()) {
    3. // Apply and end up panning
    4. if (qwtpltpnMain_->isVisible()) {
    5. Qt::MouseButton pannerButton;
    6. Qt::KeyboardModifiers pannerModifiers;
    7. qwtpltpnMain_->getMouseButton(pannerButton, pannerModifiers);
    8.  
    9. // Force QwtPlotPanner ends up via sending the proper event. This event after
    10. // processing by QwtPlotPanner appears here, due to QwtPlotPanner propagates it
    11. // further, but that event does not trigger any action (e.g. cursor moving) due to
    12. // pannerModifiers in the event.
    13. QMouseEvent endPanning(QEvent::MouseButtonRelease,
    14. qwtpltMain_->canvas()->mapFromGlobal(QCursor::pos()), pannerButton,
    15. pannerButton, pannerModifiers);
    16. QCoreApplication::sendEvent(qwtpltMain_->canvas(), &endPanning);
    17.  
    18. //##note: Aborting panning might be done with this event:
    19. //QKeyEvent endPanning(QEvent::KeyPress, pannerKey, pannerModifiers);
    20. //QCoreApplication::sendEvent(qwtpltMain_->canvas(), &endPanning);
    21. }
    22.  
    23. // Cancel zooming
    24. if (qwtpltzmMain_->isActive()) {
    25. // Force QwtPlotZoomer cancels via sending the proper event. This event after
    26. // processing by QwtPlotZoomer appears here, due to QwtPlotZoomer propagates it
    27. // further.
    28. //##assume: Qt::Key_Escape is QwtEventPattern::KeyAbort.
    29. QKeyEvent endZooming(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
    30. Q_ASSERT(qwtpltzmMain_->keyMatch(QwtEventPattern::KeyAbort, &endZooming));
    31. QCoreApplication::sendEvent(qwtpltMain_->canvas(), &endZooming);
    32.  
    33. //##note: Applying zooming and ending might be done with this event:
    34. //##assume: Qt::LeftButton is QwtEventPattern::MouseSelect1.
    35. //QMouseEvent endZooming(QEvent::MouseButtonRelease,
    36. // qwtpltMain_->canvas()->mapFromGlobal(QCursor::pos()), Qt::LeftButton,
    37. // Qt::LeftButton, Qt::NoModifier);
    38. // Q_ASSERT(qwtpltzmMain_->mouseMatch(QwtEventPattern::MouseSelect1, &endZooming));
    39. }
    40. ...
    To copy to clipboard, switch view to plain text mode 


    Added after 17 minutes:


    Probably, it might be sufficient to handle QEvent::Leave event, which occurs regardsless of whether a widget can get focus or cannot (NoFocus policy). I.e. QwtPlotPannel/QwtPlotZoomer might handle QEvent::Leave event and do there graceful ending up (applying for panning and cancelling for zooming, I beleive).
    Last edited by Alekon; 18th October 2020 at 15:01.

Similar Threads

  1. Replies: 6
    Last Post: 5th February 2019, 07:35
  2. QML TextInput never loses focus
    By Non in forum Newbie
    Replies: 1
    Last Post: 18th September 2018, 20:03
  3. Replies: 1
    Last Post: 7th May 2015, 21:58
  4. Replies: 4
    Last Post: 10th June 2010, 14:31
  5. QWinwidget loses focus
    By salix in forum Qt Programming
    Replies: 0
    Last Post: 16th June 2009, 22:54

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.