TargetItem#
- class pyqtgraph.TargetItem(pos=None, size=10, 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, 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.pen (
QPen,tuple,listorstr) – 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,listorstr) – Brush to use to fill the symbol when hovering over it. Can be any arguments that is valid formkBrush(). Default is transparent blue.symbol (
QPainterPathorstr) – 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,strorcollections.abc.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 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. SeeTargetLabelandTextItem
- label()[source]#
Provides the TargetLabel if it exists
- Returns:
If a TargetLabel exists for this TargetItem, return that, otherwise return None
- Return type:
TargetLabelorNone
- pos()[source]#
Provides the current position of the TargetItem
- Returns:
pg.Point of the current position of the TargetItem
- Return type:
- 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 (
Callableorstr, 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)[source]#
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)[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 (
strorcollections.abc.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 Noneoffset (
tupleorlistorQPointForQPoint) – Position to set the anchor of the TargetLabel away from the center of the target in pixels, by default it is (20, 0).anchor (
tupleorlistorQPointForQPoint) – Position to rotate the TargetLabel about, and position to set the offset value to seeTextItemfor more information.kwargs (
dict) – kwargs contains arguments that are passed ontoTextItemconstructor, 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 (
Callableorstr) – 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