TargetItem#
- class pyqtgraph.TargetItem(
- pos=None,
- size=10,
- symbol='crosshair',
- pen=None,
- hoverPen=None,
- brush=None,
- hoverBrush=None,
- movable=True,
- label=None,
- labelOpts=None,
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,
- symbol='crosshair',
- pen=None,
- hoverPen=None,
- brush=None,
- hoverBrush=None,
- movable=True,
- label=None,
- labelOpts=None,
- 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.pen (
QPen
,tuple
,list
orstr
) – Pen to use when drawing line. Can be any arguments that are valid formkPen()
. Default pen is transparent yellow.brush (
QBrush
,tuple
,list
, orstr
) – Defines the brush that fill the symbol. Can be any arguments that is valid formkBrush()
. Default is transparent blue.movable (
bool
) – If True, the symbol can be dragged to a new position by the user.hoverPen (
QPen
,tuple
,list
, orstr
) – Pen to use when drawing symbol when hovering over it. Can be any arguments that are valid formkPen()
. Default pen is red.hoverBrush (
QBrush
,tuple
,list
orstr
) – Brush to use to fill the symbol when hovering over it. Can be any arguments that is valid formkBrush()
. Default is transparent blue.symbol (
QPainterPath
orstr
) – 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 bysetSymbol()
label (
bool
,str
orCallable
, 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 isx = {: >.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. SeeTargetLabel
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
orNone
- pos()[source]#
Provides the current position of the TargetItem
- Returns:
pg.Point of the current position of the TargetItem
- Return type:
- setBrush(
- *args,
- **kwargs,
Set the brush that fills the symbol. Allowable arguments are any that are valid for
mkBrush()
.
- setHoverBrush(
- *args,
- **kwargs,
Set the brush that fills the symbol when hovering over it. Allowable arguments are any that are valid for
mkBrush()
.
- setHoverPen(
- *args,
- **kwargs,
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,
Method to call to enable or disable the TargetLabel for displaying text
- Parameters:
text (
Callable
orstr
, 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 oftext(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 (
dict
, optional) – These arguments are passed on toTextItem
- setPen(
- *args,
- **kwargs,
Set the pen for drawing the symbol. Allowable arguments are any that are valid for
mkPen()
.
TargetLabel#
- class pyqtgraph.TargetLabel(
- target,
- text='',
- offset=(20, 0),
- anchor=(0, 0.5),
- **kwargs,
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
orCallable
,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 Noneoffset (
tuple
orlist
orQPointF
orQPoint
) – 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
orlist
orQPointF
orQPoint
) – Position to rotate the TargetLabel about, and position to set the offset value to seeTextItem
for more information.kwargs (
dict
) – kwargs contains arguments that are passed ontoTextItem
constructor, excluding text parameter
- setFormat(
- text,
Method to set how the TargetLabel should display the text. This method should be called from TargetItem.setLabel directly.
- Parameters:
text (
Callable
orstr
) – Details how to format the text. If Callable, then the label will display the result oftext(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