Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot put a text a TextItem on a CurveArrow #2866

Open
CastorCast opened this issue Oct 31, 2023 · 1 comment
Open

Cannot put a text a TextItem on a CurveArrow #2866

CastorCast opened this issue Oct 31, 2023 · 1 comment

Comments

@CastorCast
Copy link

CastorCast commented Oct 31, 2023

Short description

I'm trying to set a CurveArrow item as parent of a TextItem, as in "Text.py" example (in Text.py it's a CurvePoint that is use as a parent of TextItem). So I have tried for a first time to modify CurveArrow in CurvePoint.py by adding a TextItem, but the text wasn't displaying, so I put the modification in my copy of the example and putting in comment the modification I made.

Code to reproduce

in CurvePoint.py :

import weakref
from math import atan2, degrees

from ..functions import clip_scalar
from ..Qt import QtCore, QtWidgets
from . import ArrowItem, TextItem, LabelItem
from .GraphicsObject import GraphicsObject

...

class CurveArrow(CurvePoint):
    """Provides an arrow that points to any specific sample on a PlotCurveItem.
    Provides properties that can be animated."""
    
    def __init__(self, curve, index=0, rotate=True, pos=None, **opts):
        CurvePoint.__init__(self, curve, index=index, pos=pos, rotate=rotate)
        if opts.get('pxMode', True):
            opts['pxMode'] = False
            self.setFlags(self.flags() | self.GraphicsItemFlag.ItemIgnoresTransformations)
        # opts['angle'] = 0
        # self.Text = TextItem.TextItem("Test", anchor=(0.5, -1.0))
        # self.Text.setParentItem(self)
        self.arrow = ArrowItem.ArrowItem(**opts)
        self.arrow.setParentItem(self)
        # print(self.Text)
        
    def setStyle(self, **opts):
        return self.arrow.setStyle(**opts)

in TestText.py :

import numpy as np

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore

x = np.linspace(-20, 20, 1000)
y = np.sin(x) / x
plot = pg.plot()   ## create an empty plot widget
plot.setYRange(-1, 2)
plot.setWindowTitle('pyqtgraph example: text')
curve = plot.plot(x,y)  ## add a single curve

# Create an animated arrow (cursor) that track the curve 
curvePoint = pg.CurveArrow(curve, rotate=False, angle=90)
plot.addItem(curvePoint)
# Configure the TextItem
Text = pg.TextItem("test", anchor=(0.5, -1.0))
Text.setParentItem(curvePoint)

## update position every 10ms
index = 0
def update():
    global curvePoint, index
    index = (index + 1) % len(x)
    curvePoint.setPos(float(index)/(len(x)-1))
    # text2.setText('[%0.1f, %0.1f]' % (x[index], y[index]))
    # curvePoint.Text('[%0.1f, %0.1f]' % (x[index], y[index]))
    Text.setText('[%0.1f, %0.1f]' % (x[index], y[index]))
    
timer = QtCore.QTimer()
timer.timeout.connect(update)
timer.start(10)

if __name__ == '__main__':
    pg.exec()

Expected behavior

I should have the same behavior as the example "Text.py", so an arrow and a text that are animated and follow the sinc(x).

Real behavior

I have the arrow that is animated and follows the curve, but I don't have any text that notifies me about the position of the arrow on the curve. Additionally, I'm using this example to identify an error in one of my scripts: It's a simple script that adds a CurveArrow to a curve. I encountered this error while using the modified CurveArrow. :

QWinFontEngine: unable to query transformed glyph metrics (GetGlyphOutline() failed, error 1003)... (Impossible dÆaccomplir cette fonction.)
QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setCompositionMode: Painter not active
QPainter::end: Painter not active, aborted

Tested environment(s)

  • PyQtGraph version: <0.13.3>
  • Qt Python binding: <PyQt5 5.15.4 Qt 5.15.2>
  • Python version: Python 3.10.6
  • NumPy version: <1.24.2>
  • Operating system: Windows 11
  • Installation method: pip

Additional context

I thank you in advance for any help
Edit1 : I forgot to tell that I add the argument "rotate" with default value "True" and put the line "opts['angle'] = 0" as I wanted to have something like CurvePoint.

@pijyoi
Copy link
Contributor

pijyoi commented Nov 13, 2023

The lines that make a CurveArrow different from a CurvePoint.
If you comment them out, the text shows up.

if opts.get('pxMode', True):
opts['pxMode'] = False
self.setFlags(self.flags() | self.GraphicsItemFlag.ItemIgnoresTransformations)
opts['angle'] = 0

From what I understand, their purpose is to make the arrow be at a tangential angle to the curve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants