Hi,

I think you want to change the anchor point of the label? In that case 
there is an anchor property of TextItems like the InfiniteLineLabel. 
Although it is not listed on the API documents for some reason (
http://www.pyqtgraph.org/documentation/graphicsItems/textitem.html), there 
does appear to be a setAnchor() method in the code (
http://www.pyqtgraph.org/documentation/_modules/pyqtgraph/graphicsItems/TextItem.htm
l).
I think maybe a self.label.setAnchor(0, 0) is what you might be after.

Patrick

On Friday, 12 April 2019 00:15:12 UTC+9:30, [email protected] wrote:
>
> I am annotating key events in my plots by overlaying them with static 
> vertical lines with labels. A mouse hover event expands the label to 
> provide more data. Both labels (default and expanded) contain multiple 
> lines.
> This is done with the following approach:
>
> class VerticalLineAnnotation(pyqtgraph.InfiniteLine):
> ...
> def hoverEvent(self, ev):
>     if ev.isExit():
>         self._expand_label(False)
>     else:
>         self._expand_label(True)
>     super().hoverEvent(ev)
> ...
> def _expand_label(self, expand):
>     if self._expanded_label == expand:
>         return
>     self._expanded_label = expand
>     if expand:
>         self.label.setFormat(self._hover_label)
>     else:
>         self.label.setFormat(self._default_label)
>     self.update()
>
>
> However, I currently must also adjust the position of the label since its 
> height changes:
>
> def _expand_label(self, expand):
>     if self._expanded_label == expand:
>         return
>     self._expanded_label = expand
>     if expand:
>         self._label_pos = self.label.orthoPos
>         self.label.setFormat(self._hover_label)
>         self.label.setPosition(self._label_pos + 
> self._hover_label_pos_offset)
>     else:
>         self._label_pos = self.label.orthoPos - 
> self._hover_label_pos_offset
>         self.label.setFormat(self._default_label)
>         self.label.setPosition(self._label_pos)
>     self.update()
>
>
> Furthermore, if the size of the plot item changes, then the location of 
> the label also changes, since I cannot use `position=1` (do to the multiple 
> lines).
>
> This problem can be solved if I were able to align the top left corner of 
> the label at `position` instead of the text item's vertical center.
> How would I make that change? Or better yet, can this be added as a 
> feature specified in labelOpts?
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/483f388e-5b6d-4e5b-9bbd-85f40dea05f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to