Thank you Ludovic for the helpful example. I came to this need and made it
an opengl item, which is similar to other existing items and fit in my
project better. Then I put it into my fork of the pyqtgraph GitHub repo; I
will see to make a PR of it if it can help others.
import pyqtgraph.opengl as gl
from pyqtgraph.opengl.GLGraphicsItem import GLGraphicsItem
from pyqtgraph.Qt import QtCore, QtGui
class GLTextItem(GLGraphicsItem):
def __init__(self, X=None, Y=None, Z=None, text=None):
GLGraphicsItem.__init__(self)
self.text = text
self.X = X
self.Y = Y
self.Z = Z
def setGLViewWidget(self, GLViewWidget):
self.GLViewWidget = GLViewWidget
def setText(self, text):
self.text = text
self.update()
def setX(self, X):
self.X = X
self.update()
def setY(self, Y):
self.Y = Y
self.update()
def setZ(self, Z):
self.Z = Z
self.update()
def paint(self):
self.GLViewWidget.qglColor(QtCore.Qt.white)
self.GLViewWidget.renderText(self.X, self.Y, self.Z, self.text)
def main():
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 40
w.show()
t = GLTextItem(X=0, Y=5, Z=10, text="Your text")
t.setGLViewWidget(w)
w.addItem(t)
g = gl.GLGridItem()
w.addItem(g)
app.exec_()
if __name__ == '__main__':
main()
On Monday, May 30, 2016 at 1:08:52 AM UTC-5, Ludovic Angot-Petit wrote:
> The only hint I can provide is from here:
> https://groups.google.com/d/msg/pyqtgraph/FNxcMh3M6nc/XGS2C447n_MJ
>
> It works for me but I don't know how to add multiple text instances, if
> you or any one knows, thanks to help!
>
> Here is a simple working example based on the above:
> import pyqtgraph.opengl as gl
> import pyqtgraph as pg
> from pyqtgraph.Qt import QtCore as pqc
> from pyqtgraph.Qt import QtGui as pqg
>
> class MyGLView(gl.GLViewWidget):
> def __init__(self, X,Y,Z,text):
> super(MyGLView, self).__init__()
> self.text = text
> self.X = X
> self.Y = Y
> self.Z = Z
>
> def setText(self, text):
> self.text = text
> self.update()
>
> def setX(self, X):
> self.X = X
> self.update()
>
> def setY(self, Y):
> self.Y = Y
> self.update()
>
> def setZ(self, Z):
> self.Z = Z
> self.update()
>
> def paintGL(self, *args, **kwds):
> gl.GLViewWidget.paintGL(self, *args, **kwds)
> self.qglColor(Qt.white)
> self.renderText(self.X, self.Y, self.Z, self.text)
>
> app = pqg.QApplication([])
> w = MyGLView(X=0,Y=5,Z=0,text="Your text")
>
> g = gl.GLGridItem()
> w.addItem(g)
>
> w.show()
>
> if __name__ == '__main__':
> pqg.QApplication.instance().exec_()
>
> Ludovic
>
--
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/60f82776-5fb8-478e-bfc6-7b9537a9368d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.