Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
94 views
in Technique[技术] by (71.8m points)

python - Updating the color of a GLMeshItem

I've been trying to update the color of a GLMeshItem in a 3d pyqtgraph plot with some success. Using the setColor() member of the GLMeshItem class, I can set the color initially, and sometimes, the face color of the mesh will update, but not always.

I've had this working in the past, so I know it is possible to do, but can't seem to figure it out this time. According to the documentation, setColor() will Set the default color to use when no vertex or face colors are specified. I'm a bit confused as to whether this means I can dynamically change colors, or only set the color initially.

For context, I have a 3d plot with a mesh in it. I read date from a file, then want to set the color of the mesh based on that data. I can post more code if needed, but my program is several hundred lines long and would be tricky to extract the necessary bits to make to problem reproducible. If it would help I can definitely do that however. For now here is the line I am using to set the color:

_mesh_model is a GLMeshItem. Color is a tuple of the form (R, G, B, Alpha)

self._mesh_model.setColor(color)

question from:https://stackoverflow.com/questions/65875040/updating-the-color-of-a-glmeshitem

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Ok after some searching I figured it out.

Instead of self._mesh_model.setColor(color), where color is a tuple in the form RGBA, I used this: QtGui.QColor(R, G, B) where R, G and B are values between 0 and 255.

Now the mesh color updates as expected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...