Title: [Bug]: AttributeError: 'QResizeEvent' object has no attribute 'pos' · Issue #22409 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: AttributeError: 'QResizeEvent' object has no attribute 'pos' · Issue #22409 · matplotlib/matplotlib
X Title: [Bug]: AttributeError: 'QResizeEvent' object has no attribute 'pos' · Issue #22409 · matplotlib/matplotlib
Description: Bug summary This bug is similar to #11607. In my case, I get it when I combine PyQt5 and matplotlib 3.5.1. In any of the other combinations (PyQt5 and matplotlib==3.4.3 or PyQt6 and matplotlib==3.5.1) it works as expected. Code for repro...
Open Graph Description: Bug summary This bug is similar to #11607. In my case, I get it when I combine PyQt5 and matplotlib 3.5.1. In any of the other combinations (PyQt5 and matplotlib==3.4.3 or PyQt6 and matplotlib==3.5...
X Description: Bug summary This bug is similar to #11607. In my case, I get it when I combine PyQt5 and matplotlib 3.5.1. In any of the other combinations (PyQt5 and matplotlib==3.4.3 or PyQt6 and matplotlib==3.5...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22409
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: AttributeError: 'QResizeEvent' object has no attribute 'pos' ","articleBody":"### Bug summary\n\nThis bug is similar to #11607. In my case, I get it when I combine PyQt5 and matplotlib 3.5.1. In any of the other combinations (PyQt5 and matplotlib==3.4.3 or PyQt6 and matplotlib==3.5.1) it works as expected.\r\n\n\n### Code for reproduction\n\n```python\n# change this to use PyQt5 or PyQt6\r\nqt = 'qt5'\r\n\r\nimport sys\r\nimport matplotlib\r\nfrom matplotlib.figure import Figure\r\nif qt == 'qt6':\r\n from PyQt6.QtWidgets import *\r\n from PyQt6.QtCore import *\r\n from PyQt6.QtGui import *\r\n if matplotlib.__version__ == '3.4.3':\r\n raise ValueError('For PyQt6 Install matplotlib 3.5.1')\r\n from matplotlib.backends.backend_qtagg import (FigureCanvas, NavigationToolbar2QT as NavigationToolbar)\r\n\r\n\r\nelse:\r\n from PyQt5.QtWidgets import *\r\n from PyQt5.QtCore import *\r\n from matplotlib.backends.backend_qt5agg import (FigureCanvasQTAgg as FigureCanvas,\r\n NavigationToolbar2QT as NavigationToolbar)\r\nimport numpy as np\r\n\r\nprint('Matplotlib version:', matplotlib.__version__)\r\n\r\n\r\nclass ChartsBase(QMdiSubWindow):\r\n def __init__(self):\r\n super(ChartsBase, self).__init__()\r\n self.setMinimumSize(400, 400)\r\n\r\n self.mainwidgetmdi = QMainWindow() # must be QMainWindow to handle the toolbar\r\n self.setWidget(self.mainwidgetmdi)\r\n\r\n fig = Figure()\r\n self.figure_canvas = FigureCanvas(fig)\r\n self.fig = self.figure_canvas.figure\r\n self.mainwidgetmdi.setCentralWidget(self.figure_canvas)\r\n # similar to figure canvas\r\n self.mpl_toolbar = NavigationToolbar(self.figure_canvas, self)\r\n self.mpl_toolbar.setVisible(True)\r\n if qt == 'qt6':\r\n area = Qt.ToolBarArea.BottomToolBarArea\r\n else:\r\n area = Qt.BottomToolBarArea\r\n self.mainwidgetmdi.addToolBar(area, self.mpl_toolbar)\r\n\r\n t = np.linspace(0, 10, 501)\r\n\r\n self.axes = self.fig.subplots(1, 1)\r\n line_plot_ax = self.axes.plot(t)\r\n\r\n\r\nclass MDIWindow(QMainWindow):\r\n count = 0\r\n\r\n def __init__(self):\r\n super().__init__()\r\n\r\n self.mdi = QMdiArea()\r\n self.setCentralWidget(self.mdi)\r\n bar = self.menuBar()\r\n\r\n file = bar.addMenu(\"File\")\r\n file.addAction(\"New\")\r\n file.triggered[QAction].connect(self.add_new)\r\n self.setWindowTitle(\"MDI Application with matplotlib\")\r\n\r\n def add_new(self, p):\r\n\r\n if p.text() == \"New\":\r\n sub = ChartsBase()\r\n sub.setWindowTitle(\"Matplotlib example\")\r\n self.mdi.addSubWindow(sub)\r\n sub.show()\r\n\r\nif __name__ == '__main__':\r\n app = QApplication(sys.argv)\r\n mdi = MDIWindow()\r\n mdi.show()\r\n sys.exit(app.exec())\n```\n\n\n### Actual outcome\n\nTo reproduce:\r\n1. execute the app\r\n2. Menu \"File\"\r\n3. \"New\"\r\n4. Maximize the subwindow\r\n\r\nWhen the subwindow is maximized I get this error:\r\n```\r\nTraceback (most recent call last):\r\n File \"/home/mario/programs/miniconda/lib/python3.8/site-packages/matplotlib/backends/backend_qt.py\", line 262, in enterEvent\r\n x, y = self.mouseEventCoords(self._get_position(event))\r\nAttributeError: 'QResizeEvent' object has no attribute 'pos'\r\n```\n\n### Expected outcome\n\nThe maximized subwindow\n\n### Additional information\n\n\u003e What are the conditions under which this bug happens? input parameters, edge cases, etc?\r\n\r\nUsing `matplotlib==3.5.1` with `PyQt5`. Not happen with other combinations `matplotlib==3.5.1` and `PyQt6` or `matplotlib==3.4.3` and `PyQt5`\r\n\r\n\u003e Do you know why this bug is happening?\r\n\r\nThis bug is related to the QEvents methods. QResizeEvent does have not any method to get the position in PyQt5, unlike PyQt6 which does have it\r\n\r\n\u003e Do you maybe even know a fix?\r\n\r\nAdd a try-except clausule to this method\r\nhttps://github.com/matplotlib/matplotlib/blob/60d0c33e445a33463d301957d5ee4e97c7565a59/lib/matplotlib/backends/backend_qt.py#L264-L266\r\n```python\r\ndef enterEvent(self, event):\r\n try:\r\n x, y = self.mouseEventCoords(self._get_position(event))\r\n except AttributeError:\r\n # QResizeEvent has no attribute pos\r\n x = y = None\r\n FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y))\r\n```\r\nAfter this, work as expected!\r\nHappy to open a PR if it is needed!\r\n\n\n### Operating system\n\nLinux Mint 20.2\n\n### Matplotlib Version\n\n3.5.1\n\n### Matplotlib Backend\n\nQtAgg\n\n### Python version\n\nPython 3.8.5\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/Valdes-Tresanco-MS","@type":"Person","name":"Valdes-Tresanco-MS"},"datePublished":"2022-02-05T19:21:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/22409/matplotlib/issues/22409"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:37b488a8-8210-ba3b-bc8d-3c9cfc93fc45 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AE6C:BDE76:4F1EC1E:6E9EF10:6A50F803 |
| html-safe-nonce | 0ab712dba5684082c7e5cc53df027c636ed7e0003af2e546cbfbedeac410467e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRTZDOkJERTc2OjRGMUVDMUU6NkU5RUYxMDo2QTUwRjgwMyIsInZpc2l0b3JfaWQiOiIyMzEzODU5ODMzNzQzMzQxNTcxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cf1245b3bcd8b04b39f13ec5421eaf51ceb030babf2e20eff26d957df4e0ae08 |
| hovercard-subject-tag | issue:1125010830 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/22409/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4dac8ee2e56946319578d4467fa62f43d01fe05fa3a312066009edb60e9c1560/matplotlib/matplotlib/issues/22409 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4dac8ee2e56946319578d4467fa62f43d01fe05fa3a312066009edb60e9c1560/matplotlib/matplotlib/issues/22409 |
| og:image:alt | Bug summary This bug is similar to #11607. In my case, I get it when I combine PyQt5 and matplotlib 3.5.1. In any of the other combinations (PyQt5 and matplotlib==3.4.3 or PyQt6 and matplotlib==3.5... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Valdes-Tresanco-MS |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5266e58c17a510c403505cc811606465e90a881d2007ee7df1c4800d5c659838 |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8d836581d020676cc0ef4a83cd2fe17e4af02c3d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width