Instances of this class are delivered to items in a :class:`GraphicsScene <pyqtgraph.GraphicsScene>` via their mouseDragEvent() method when the item is being mouse-dragged.
"""Return any keyboard modifiers currently pressed.
(see QGraphicsSceneMouseEvent::modifiers in the Qt documentation)
"""
returnself._modifiers
classMouseClickEvent:
"""
Instances of this class are delivered to items in a :class:`GraphicsScene <pyqtgraph.GraphicsScene>` via their mouseClickEvent() method when the item is clicked.
"""
def__init__(self,pressEvent,double=False):
self.accepted=False
self.currentItem=None
...
...
@@ -106,37 +163,60 @@ class MouseClickEvent:
defaccept(self):
"""An item should call this method if it can handle the event. This will prevent the event being delivered to any other items."""
self.accepted=True
self.acceptedItem=self.currentItem
defignore(self):
"""An item should call this method if it cannot handle the event. This will allow the event to be delivered to other items."""
self.accepted=False
defisAccepted(self):
returnself.accepted
defscenePos(self):
"""Return the current scene position of the mouse."""
returnPoint(self._scenePos)
defscreenPos(self):
"""Return the current screen position (pixels relative to widget) of the mouse."""
returnPoint(self._screenPos)
defbuttons(self):
"""
Return the buttons currently pressed on the mouse.
(see QGraphicsSceneMouseEvent::buttons in the Qt documentation)
"""
returnself._buttons
defbutton(self):
"""Return the mouse button that generated the click event.
(see QGraphicsSceneMouseEvent::button in the Qt documentation)
"""
returnself._button
defdouble(self):
"""Return True if this is a double-click."""
returnself._double
defpos(self):
"""
Return the current position of the mouse in the coordinate system of the item
"""Return any keyboard modifiers currently pressed.
(see QGraphicsSceneMouseEvent::modifiers in the Qt documentation)
"""
returnself._modifiers
def__repr__(self):
...
...
@@ -150,8 +230,9 @@ class MouseClickEvent:
classHoverEvent:
"""
Instances of this class are delivered to items in a :class:`GraphicsScene <pyqtgraph.GraphicsScene>` via their hoverEvent() method when the mouse is hovering over the item.
This event class both informs items that the mouse cursor is nearby and allows items to
communicate with one another about whether each item will accept _potential_ mouse events.
communicate with one another about whether each item will accept *potential* mouse events.
It is common for multiple overlapping items to receive hover events and respond by changing
their appearance. This can be misleading to the user since, in general, only one item will
...
...
@@ -188,13 +269,21 @@ class HoverEvent:
defisEnter(self):
"""Returns True if the mouse has just entered the item's shape"""
returnself.enter
defisExit(self):
"""Returns True if the mouse has just exited the item's shape"""
returnself.exit
defacceptClicks(self,button):
""""""
"""Inform the scene that the item (that the event was delivered to)
would accept a mouse click event if the user were to click before
moving the mouse again.
Returns True if the request is successful, otherwise returns False (indicating
that some other item would receive an incoming click).
"""
ifnotself.acceptable:
returnFalse
ifbuttonnotinself.__clickItems:
...
...
@@ -203,6 +292,13 @@ class HoverEvent:
returnFalse
defacceptDrags(self,button):
"""Inform the scene that the item (that the event was delivered to)
would accept a mouse drag event if the user were to drag before
the next hover event.
Returns True if the request is successful, otherwise returns False (indicating
that some other item would receive an incoming drag event).
"""
ifnotself.acceptable:
returnFalse
ifbuttonnotinself.__dragItems:
...
...
@@ -211,24 +307,40 @@ class HoverEvent:
returnFalse
defscenePos(self):
"""Return the current scene position of the mouse."""
returnPoint(self._scenePos)
defscreenPos(self):
"""Return the current screen position of the mouse."""
returnPoint(self._screenPos)
deflastScenePos(self):
"""Return the previous scene position of the mouse."""
returnPoint(self._lastScenePos)
deflastScreenPos(self):
"""Return the previous screen position of the mouse."""
returnPoint(self._lastScreenPos)
defbuttons(self):
"""
Return the buttons currently pressed on the mouse.
(see QGraphicsSceneMouseEvent::buttons in the Qt documentation)
"""
returnself._buttons
defpos(self):
"""
Return the current position of the mouse in the coordinate system of the item
@@ -17,7 +17,7 @@ Pyqtgraph makes it very easy to visualize data from the command line. Observe::
import pyqtgraph as pg
pg.plot(data) # data can be a list of values or a numpy array
The example above would open a window displaying a line plot of the data given. I don't think it could reasonably be any simpler than that. The call to pg.plot returns a handle to the plot widget that is created, allowing more data to be added to the same window.
The example above would open a window displaying a line plot of the data given. The call to :func:`pg.plot <pyqtgraph.plot>` returns a handle to the :class:`plot widget <pyqtgraph.PlotWidget>` that is created, allowing more data to be added to the same window.
Further examples::
...
...
@@ -43,5 +43,5 @@ While I consider this approach somewhat lazy, it is often the case that 'lazy' i
Embedding widgets inside PyQt applications
------------------------------------------
For the serious application developer, all of the functionality in pyqtgraph is available via widgets that can be embedded just like any other Qt widgets. Most importantly, see: PlotWidget, ImageView, GraphicsView, GraphicsLayoutWidget. Pyqtgraph's widgets can be included in Designer's ui files via the "Promote To..." functionality.
For the serious application developer, all of the functionality in pyqtgraph is available via widgets that can be embedded just like any other Qt widgets. Most importantly, see: :class:`PlotWidget <pyqtgraph.PlotWidget>`, :class:`ImageView <pyqtgraph.ImageView>`, :class:`GraphicsLayoutWidget <pyqtgraph.GraphicsLayoutWidget>`, and :class:`GraphicsView <pyqtgraph.GraphicsView>`. Pyqtgraph's widgets can be included in Designer's ui files via the "Promote To..." functionality.
@@ -44,8 +44,8 @@ This will start a launcher with a list of available examples. Select an item fro
How does it compare to...
-------------------------
* matplotlib: For plotting and making publication-quality graphics, matplotlib is far more mature than pyqtgraph. However, matplotlib is also much slower and not suitable for applications requiring realtime update of plots/video or rapid interactivity. It also does not provide any of the GUI tools and image interaction/slicing functionality in pyqtgraph.
* matplotlib: For plotting, pyqtgraph is not nearly as complete/mature as matplotlib, but runs much faster. Matplotlib is more aimed toward making publication-quality graphics, whereas pyqtgraph is intended for use in data acquisition and analysis applications. Matplotlib is more intuitive for matlab programmers; pyqtgraph is more intuitive for python/qt programmers. Matplotlib (to my knowledge) does not include many of pyqtgraph's features such as image interaction, volumetric rendering, parameter trees, flowcharts, etc.
* pyqwt5: pyqwt is generally more mature than pyqtgraph for plotting and is about as fast. The major differences are 1) pyqtgraph is written in pure python, so it is somewhat more portable than pyqwt, which often lags behind pyqt in development (and can be a pain to install on some platforms) and 2) like matplotlib, pyqwt does not provide any of the GUI tools and image interaction/slicing functionality in pyqtgraph.
* pyqwt5: About as fast as pyqwt5, but not quite as complete for plotting functionality. Image handling in pyqtgraph is much more complete (again, no ROI widgets in qwt). Also, pyqtgraph is written in pure python, so it is more portable than pyqwt, which often lags behind pyqt in development (I originally used pyqwt, but decided it was too much trouble to rely on it as a dependency in my projects). Like matplotlib, pyqwt (to my knowledge) does not include many of pyqtgraph's features such as image interaction, volumetric rendering, parameter trees, flowcharts, etc.
(My experience with these libraries is somewhat outdated; please correct me if I am wrong here)