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

PlotItem.scene() has a QGraphicsScene type hint instead of a pyqtgraph.GraphicsScene #3024

Open
Antyos opened this issue May 10, 2024 · 0 comments

Comments

@Antyos
Copy link

Antyos commented May 10, 2024

Short description

PlotItem.scene() has a type hint of QGraphicsScene | None instead of a pyqtgraph.GraphicsScene. This raises an error when trying to access signals from the scene, such as sigMouseMoved.

Code to reproduce

This is an abridged snippet of code from the crosshair.py example:

import pyqtgraph as pg

def mouseMoved(evt):
    pass

p = pg.PlotItem()
p.scene().sigMouseMoved.connect(mouseMoved)
#         ^^^^^^^^^^^^^  Cannot access attribute "sigMouseMoved" for class "QGraphicsScene"
#                          Attribute "sigMouseMoved" is unknown

Proposed Solution

I think this can be fixed by adding a type hint to the GraphicsWidget class:

from typing import TYPE_CHECKING

class GraphicsWidget(GraphicsItem, QtWidges.QGraphicsWidget):
    # ...
    if TYPE_CHECKING:
        def scene(self) -> pyqtgraph.GraphicsScene: ...

If this seems reasonable, I can draft a PR.

Tested environment(s)

  • PyQtGraph version: 0.13.5 and 0.13.7
  • Qt Python binding: PyQt6
  • Python version: 3.12.2
  • NumPy version: 1.26.4
  • Operating system: Windows 10
  • Installation method: Poetry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants