TargetItem¶
-
class
pyqtgraph.
TargetItem
(pos=None, size=10, radii=None, symbol='crosshair', pen=None, hoverPen=None, brush=None, hoverBrush=None, movable=True, label=None, labelOpts=None)[source]¶ Draws a draggable target symbol (circle plus crosshair).
The size of TargetItem will remain fixed on screen even as the view is zoomed. Includes an optional text label.
-
__init__
(pos=None, size=10, radii=None, symbol='crosshair', pen=None, hoverPen=None, brush=None, hoverBrush=None, movable=True, label=None, labelOpts=None)[source]¶ - Parameters
pos (list, tuple, QPointF, QPoint, Optional) – Initial position of the symbol. Default is (0, 0)
size (int) – Size of the symbol in pixels. Default is 10.
radii (tuple of int) – Deprecated. Gives size of crosshair in screen pixels.
pen (QPen, tuple, list or str) – Pen to use when drawing line. Can be any arguments that are valid for
mkPen()
. Default pen is transparent yellow.brush (QBrush, tuple, list, or str) – Defines the brush that fill the symbol. Can be any arguments that is valid for
mkBrush()
. Default is transparent blue.movable (bool) – If True, the symbol can be dragged to a new position by the user.
hoverPen (QPen, tuple, list, or str) – Pen to use when drawing symbol when hovering over it. Can be any arguments that are valid for
mkPen()
. Default pen is red.hoverBrush (QBrush, tuple, list or str) – Brush to use to fill the symbol when hovering over it. Can be any arguments that is valid for
mkBrush()
. Default is transparent blue.symbol (QPainterPath or str) – QPainterPath to use for drawing the target, should be centered at
(0, 0)
withmax(width, height) == 1.0
. Alternatively a string which can be any symbol accepted bysetData()
label (bool, str or callable, optional) – Text to be displayed in a label attached to the symbol, or None to show no label (default is None). May optionally include formatting strings to display the symbol value, or a callable that accepts x and y as inputs. If True, the label is
x = {: >.3n}\ny = {: >.3n}
False or None will result in no text being displayedlabelOpts (dict) – A dict of keyword arguments to use when constructing the text label. See
TargetLabel
andTextItem
-
label
()[source]¶ Provides the TargetLabel if it exists
- Returns
If a TargetLabel exists for this TargetItem, return that, otherwise return None
- Return type
TargetLabel or None
-
pos
()[source]¶ Provides the current position of the TargetItem
- Returns
pg.Point of the current position of the TargetItem
- Return type
Point
-
setBrush
(*args, **kwargs)[source]¶ Set the brush that fills the symbol. Allowable arguments are any that are valid for
mkBrush()
.
-
setHoverBrush
(*args, **kwargs)[source]¶ Set the brush that fills the symbol when hovering over it. Allowable arguments are any that are valid for
mkBrush()
.
-
setHoverPen
(*args, **kwargs)[source]¶ Set the pen for drawing the symbol when hovering over it. Allowable arguments are any that are valid for
mkPen()
.
-
setLabel
(text=None, labelOpts=None)[source]¶ Method to call to enable or disable the TargetLabel for displaying text
- Parameters
text (Callable or str, optional) – Details how to format the text, by default None If None, do not show any text next to the TargetItem If Callable, then the label will display the result of
text(x, y)
If a fromatted string, then the output oftext.format(x, y)
will be displayed If a non-formatted string, then the text label will displaytext
, by default NonelabelOpts (dictionary, optional) – These arguments are passed on to
TextItem
-
setPen
(*args, **kwargs)[source]¶ Set the pen for drawing the symbol. Allowable arguments are any that are valid for
mkPen()
.
-
setPos
(pos)[source]¶ Method to set the position to
(x, y)
within the plot view- Parameters
pos (tuple, list, QPointF, QPoint, or pg.Point) – Container that consists of
(x, y)
representation of where the TargetItem should be placed- Raises
TypeError – If the type of
pos
does not match the known types to extract coordinate info from, a TypeError is raised
-
TargetLabel¶
-
class
pyqtgraph.
TargetLabel
(target, text='', offset=(20, 0), anchor=(0, 0.5), **kwargs)[source]¶ A TextItem that attaches itself to a TargetItem.
This class extends TextItem with the following features : * Automatically positions adjacent to the symbol at a fixed position. * Automatically reformats text when the symbol location has changed.
- Parameters
target (TargetItem) – The TargetItem to which this label will be attached to.
text (str or callable, Optional) – Governs the text displayed, can be a fixed string or a format string that accepts the x, and y position of the target item; or be a callable method that accepts a tuple (x, y) and returns a string to be displayed. If None, an empty string is used. Default is None
offset (tuple or list or QPointF or QPoint) – Position to set the anchor of the TargetLabel away from the center of the target in pixels, by default it is (20, 0).
anchor (tuple, list, QPointF or QPoint) – Position to rotate the TargetLabel about, and position to set the offset value to see
TextItem
for more inforation.kwargs (dict of arguments that are passed on to) –
TextItem
constructor, excluding text parameter
-
setFormat
(text)[source]¶ Method to set how the TargetLabel should display the text. This method should be called from TargetItem.setLabel directly.
- Parameters
text (Callable or str) – Details how to format the text. If Callable, then the label will display the result of
text(x, y)
If a fromatted string, then the output oftext.format(x, y)
will be displayed If a non-formatted string, then the text label will displaytext