Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'QEvent' object has no attribute 'pos' #11607

Closed
anntzer opened this issue Jul 9, 2018 · 12 comments · Fixed by #11622
Closed

AttributeError: 'QEvent' object has no attribute 'pos' #11607

anntzer opened this issue Jul 9, 2018 · 12 comments · Fixed by #11622
Labels
GUI: Qt Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Jul 9, 2018

Since #9814, moving the mouse on a Qt4Agg window raises the exception

Traceback (most recent call last):
  File "/home/antony/src/extern/matplotlib/lib/matplotlib/backends/backend_qt5.py", line 294, in enterEvent
    x, y = self.mouseEventCoords(event.pos())
AttributeError: 'QEvent' object has no attribute 'pos'

(Qt5 instead uses a QEnterEvent here, which does have a pos()).

attn @lkjell

@anntzer anntzer added Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. GUI: Qt labels Jul 9, 2018
@anntzer anntzer added this to the v3.0 milestone Jul 9, 2018
@lkjell
Copy link
Contributor

lkjell commented Jul 9, 2018

Won't fix for v3.0? pyside/PySide#132 .
Not sure if this is a matplotlib bug as Qt 4.8 docs appears to be the same as Qt5.

http://doc.qt.io/archives/qt-4.8/qwidget.html#enterEvent
http://doc.qt.io/qt-5/qwidget.html#enterEvent

@anntzer
Copy link
Contributor Author

anntzer commented Jul 10, 2018

It's clearly a (big) regression, so it should be fixed.

@lkjell
Copy link
Contributor

lkjell commented Jul 10, 2018

Bug fix for 2.2.x yes but not for 3.0. Since you have qt4 can you see which position attribute is passed to the event? If there is none then that does not make sense at all.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 10, 2018

It's an object of class QEvent, which has no pos().
It would not be acceptable (IMO) to basically say "mpl3 does not support Qt4".

@lkjell
Copy link
Contributor

lkjell commented Jul 10, 2018

Qt4 is deprecated. Anyway Unless the event gives us position then a possible fix is to catch the error and pass None as coordinates. This will also be a bug where user complains why no positions are passed down.

@tacaswell
Copy link
Member

We still support Qt4 and there is about to be one more release of it. I agree with @anntzer , dropping Qt4 support for mpl3 is not an option.

The simplest fix is to just catch the exception and do x = y = None which matches the fall-back behavior in https://github.com/matplotlib/matplotlib/pull/9814/files

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jul 10, 2018
closes matplotlib#11607

The event object passed in from PyQt4 does not have a `pos` attribute.
Be forgiving of this and fallback to None.  This matches the fallback
behavior in backend_bases if xy is not passed to `enter_notify_event`.
tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jul 10, 2018
closes matplotlib#11607

The event object passed in from PyQt4 does not have a `pos` attribute.
Be forgiving of this and fallback to None.  This matches the fallback
behavior in backend_bases if xy is not passed to `enter_notify_event`.
@lkjell
Copy link
Contributor

lkjell commented Jul 11, 2018

@anntzer btw is there a problem with leaveEvent aswell?

@anntzer
Copy link
Contributor Author

anntzer commented Jul 11, 2018

No, leaveEvent() doesn't have xy info (perhaps it should?).

@noonchen
Copy link

noonchen commented Dec 3, 2021

Traceback (most recent call last):
  File "matplotlib/backends/backend_qt.py", line 262, in enterEvent
AttributeError: 'QResizeEvent' object has no attribute 'pos'

Having a similar issue in version 3.5.0, using pyqt5.

@lkjell
Copy link
Contributor

lkjell commented Dec 3, 2021

@noonchen this is a new issue after a major refactor of the code. You can see the filename has changed.
Nevertheless I do not understand why the enterEvent is triggered if you are trying to do a resize.
There exist a resizeEvent on line 334.

Could you describe what you are trying? Please also attach a sample code. Eventually create a new bug report.

@noonchen
Copy link

noonchen commented Dec 5, 2021

@lkjell Sorry for the late reply. I try to reproduce this issue but I failed to find the correct trigger, it happens once out of ~20 attempts maybe.

I am embedding the matplotlib canvas into the QTabWidget, and the canvas has enterEvent and resizeEvent callbacks connected for interaction. Based on my previous debugging experience, I noticed the resizeEvent would be triggered when I move the mouse in the figure, I'm not exactly sure why it happens, but I'm guessing it's because I used figure.canvas.restore_region and figure.canvas.copy_from_bbox in the callback functions.

@tacaswell
Copy link
Member

@noonchen can you open a new issue? Is there any more of the traceback? If it is only happening occasionally I assume that this is some sort of race condition which are fun to trace down! We could just make that code even more forgiving, but it would be better if we could understand at least what the race is between.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: Qt Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants