Try to promote your OpenGL widget on PyQt form at PyQt designer:

some hints : 
https://stackoverflow.com/questions/53798877/pyqtgraph-opengl-vs-opengl-gl-how-to-display-axis-at-pyqt5-opengl-embedded-wid



On Saturday, April 18, 2020 at 9:57:19 AM UTC-7, Daniele Dolci wrote:
>
> I am trying to create a 3d plot of a cube and add it to my ui. after lots 
> of tests and following the examples I got this code to work:
>
> # import PyQt5
> # from PyQt5 import QtGui, QtCore
> # import numpy as np
> # import pyqtgraph as pg
> # import pyqtgraph.opengl as gl
>
> # -*- coding: utf-8 -*-
> """
> Demonstrates GLVolumeItem for displaying volumetric data.
>
> """
>
> ## Add path to library (just for examples; you do not need this)
>
> from pyqtgraph.Qt import QtCore, QtGui
> import pyqtgraph.opengl as gl
>
> app = QtGui.QApplication([])
> w = gl.GLViewWidget()
> w.opts['distance'] = 200
> w.show()
> w.setWindowTitle('pyqtgraph example: GLVolumeItem')
>
> # b = gl.GLBoxItem()
> # w.addItem(b)
> g = gl.GLGridItem()
> g.scale(10, 10, 1)
> w.addItem(g)
>
> import numpy as np
>
> vertexes = np.array([[1, 0, 0], #0
>                      [0, 0, 0], #1
>                      [0, 1, 0], #2
>                      [0, 0, 1], #3
>                      [1, 1, 0], #4
>                      [1, 1, 1], #5
>                      [0, 1, 1], #6
>                      [1, 0, 1]])#7
>
> colors = np.array([[1,0,0,1] for i in range(12)])
>
> faces = np.array([[1,0,7], [1,3,7],
>                   [1,2,4], [1,0,4],
>                   [1,2,6], [1,3,6],
>                   [0,4,5], [0,7,5],
>                   [2,4,5], [2,6,5],
>                   [3,6,5], [3,7,5]])
>
> cube = gl.GLMeshItem(vertexes=vertexes, faces=faces, faceColors=colors,
>                      drawEdges=True, edgeColor=(0, 0, 0, 1))
>
> w.addItem(cube)
>
> ax = gl.GLAxisItem()
> w.addItem(ax)
>
> ## Start Qt event loop unless running in interactive mode.
> if __name__ == '__main__':
>     import sys
>
>     if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
>         QtGui.QApplication.instance().exec_()
>
>
>
> For some reason whenever I replace:
>
>
> from pyqtgraph.Qt import QtCore, QtGui
>
> with
>
> from PyQt5 import QtWidgets, QtCore, QtGui
>
>
> I start to get this error:
>
> Traceback (most recent call last):
>   File 
> "/usr/local/lib/python3.7/dist-packages/pyqtgraph/opengl/GLViewWidget.py", 
> line 188, in paintGL
>     self.setProjection(region=region)
>   File 
> "/usr/local/lib/python3.7/dist-packages/pyqtgraph/opengl/GLViewWidget.py", 
> line 110, in setProjection
>     glMatrixMode(GL_PROJECTION)
>   File "/usr/lib/python3/dist-packages/OpenGL/error.py", line 232, in 
> glCheckError
>     baseOperation = baseOperation,
> OpenGL.error.GLError: GLError(
>    err = 1282,
>    description = b'invalid operation',
>    baseOperation = glMatrixMode,
>    cArguments = (GL_PROJECTION,)
> )
>
>
> For this reason I wasn't able to get this to work in my ui. Any idea what 
> that might depend on?
>
>
> Thanks!
>
>
>
>

-- 
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/c2122d7e-5e1e-471e-9d1f-8e5789d03982%40googlegroups.com.

Reply via email to