Skip to content

convert QPointF to QPoint before calling mapToScene()#2870

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
sevas:graphicsview-qpoint-conversion
Nov 2, 2023
Merged

convert QPointF to QPoint before calling mapToScene()#2870
j9ac9k merged 1 commit intopyqtgraph:masterfrom
sevas:graphicsview-qpoint-conversion

Conversation

@sevas
Copy link
Copy Markdown
Contributor

@sevas sevas commented Nov 1, 2023

On macOS with PySide6, the following exception is raised when moving the mouse in a GraphicsView widget:

TypeError: 'PySide6.QtWidgets.QGraphicsView.mapToScene' called with wrong argument types:
  PySide6.QtWidgets.QGraphicsView.mapToScene(QPointF)
Supported signatures:
  PySide6.QtWidgets.QGraphicsView.mapToScene(PySide6.QtGui.QPainterPath)
  PySide6.QtWidgets.QGraphicsView.mapToScene(PySide6.QtCore.QPoint)
  PySide6.QtWidgets.QGraphicsView.mapToScene(Union[PySide6.QtGui.QPolygon, Sequence[PySide6.QtCore.QPoint], PySide6.QtCore.QRect])
  PySide6.QtWidgets.QGraphicsView.mapToScene(PySide6.QtCore.QRect)
  PySide6.QtWidgets.QGraphicsView.mapToScene(int, int)
  PySide6.QtWidgets.QGraphicsView.mapToScene(int, int, int, int)
Traceback (most recent call last):
  File "/Users/frederic/repos/pyqtgraph/pyqtgraph/widgets/GraphicsView.py", line 360, in mouseMoveEvent
    self.sigSceneMouseMoved.emit(self.mapToScene(lpos))

One simple workaround is converting the QPointF() to a QPoint() (as this MR does), but I do not know if this is the appropriate fix. I'm happy to check to provide another fix if this is not the correct way and someone points me to the right direction.

I have searched existing issues and MRs and I did not find a similar ticket, but I may have missed it.

Here is my environment info:

  • macOS 14.0
  • using a conda environment with python 3,11, all packages from conda-forge.
  • relevant conda packages installed:
  pyqtgraph                             0.13.3        pyhd8ed1ab_0                 conda-forge
  qt6-main                              6.6.0         h9991a84_0                   conda-forge
  pyside6                               6.6.0         py311h6a994ee_1              conda-forge

Fixes #

Other Tasks

Bump Dependency Versions

Files that need updates

Confirm the following files have been either updated or there has been a determination that no update is needed.

  • README.md
  • setup.py
  • tox.ini
  • .github/workflows/main.yml and associated requirements.txt and conda environemt.yml files
  • pyproject.toml
  • binder/requirements.txt
Pre-Release Checklist

Pre Release Checklist

  • Update version info in __init__.py
  • Update CHANGELOG primarily using contents from automated changelog generation in GitHub release page
  • Have git tag in the format of pyqtgraph-
Post-Release Checklist

Steps To Complete

  • Append .dev0 to __version__ in __init__.py
  • Announce on mail list
  • Announce on Twitter

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Nov 1, 2023

Hmm, this issue would have been present since 13d652c as part of the effort to support Qt6, which favors the use of QPointF for mouse coordinates.

This can only be triggered by enableMouse() but it looks like the library doesn't ordinarily make use of this functionality.

The view can be panned using the middle mouse button and scaled using the right mouse button if
enabled via enableMouse() (but ordinarily, we use ViewBox for this functionality)."""

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Nov 1, 2023

So probably the only example to instantiate a GraphicsView w/o also a ViewBox:
https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/examples/GradientEditor.py

If I enableMouse() there (and fix the QPointF issues), then panning works. But then the gradient editor ticks can no longer be dragged around.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 2, 2023

If I enableMouse() there (and fix the QPointF issues), then panning works. But then the gradient editor ticks can no longer be dragged around.

Would the fix there be in GradientEditor or should we look for a different mapping method that can use floating point precision?

@pijyoi
Copy link
Copy Markdown
Contributor

pijyoi commented Nov 2, 2023

I rather suspect that enabling mouse for GraphicsView had never worked with the rest of the library.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Nov 2, 2023

I rather suspect that enabling mouse for GraphicsView had never worked with the rest of the library.

yeah, I was thinking that too; anyway this PR LGTM, merging. Thanks @sevas !

@j9ac9k j9ac9k merged commit d113c12 into pyqtgraph:master Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants