Comments (9)
Hello, thanks for the quick answer, indeed it is possible, i figure it out like 20 minuts ago, i am currently expertimenting, but in breef it is just like you said, just replace PyQt5 import for PySide2 and replace pyqtsignal and pyqtslot for Signal and Slot.
My only problem it is with the scalars and cmap, you can see in the imagen that dont correspond with the height, but that's another topic. i have intendet to release the code eventually, but i cant do it right now, since it is a work for university stuff.
btw, after making those changes, the basic example of PyVista + PyQt5 works with pyside2 changing Qt for QtWidgets.
from PySide2 import QtWidgets
import numpy as np
import pyvista as pv
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None, show=True):
super(MainWindow, self).__init__(parent)
# create the frame
self.frame = QtWidgets.QFrame()
vlayout = QtWidgets.QVBoxLayout()
# add the pyvista interactor object
self.vtk_widget = pv.QtInteractor(self.frame)
vlayout.addWidget(self.vtk_widget)
self.frame.setLayout(vlayout)
self.setCentralWidget(self.frame)
# simple menu to demo functions
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
exitButton = QtWidgets.QAction('Exit', self)
exitButton.setShortcut('Ctrl+Q')
exitButton.triggered.connect(self.close)
fileMenu.addAction(exitButton)
# allow adding a sphere
meshMenu = mainMenu.addMenu('Mesh')
self.add_sphere_action = QtWidgets.QAction('Add Sphere', self)
self.add_sphere_action.triggered.connect(self.add_sphere)
meshMenu.addAction(self.add_sphere_action)
if show:
self.show()
def add_sphere(self):
""" add a sphere to the pyqt frame """
sphere = pv.Sphere()
self.vtk_widget.add_mesh(sphere)
self.vtk_widget.reset_camera()
from pyvista-support.
Yes, it is possible to embed a PyVista render window in a pyside2 app! This requires a bit of hacking but we could likely get a branch going in the main repo for this. I think simply replacing PyQt5 imports with PySide2 will do the trick
Are you familiar with PyVista’s BackgroundPlotter
class and the internalQtInteractor
class it inherits?
You’d likely need to inherit the QtInteractor
class and embed that after replacing the PyQt5 imports for PySide2
Is this GUI app you’re making open source? If so maybe we could collaborate and get a general template for embedding pyvista in PySide2 apps...
Sent with GitHawk
from pyvista-support.
Excellent work! I'm glad you were able to figure out how to get this working so quickly!
It'd be nice if we could set up PyVista to work with both. PyQt5 and PySide2 - I'll think about how we could make this work
My only problem it is with the scalars and cmap, you can see in the imagen that don't correspond with the height, but that's another topic.
Feel free to open another issue if you need help with this
from pyvista-support.
It'd be nice if we could set up PyVista to work with both. PyQt5 and PySide2 - I'll think about how we could make this work
about that, perhaps you can find inspiration in the Qt.py file of pyqtgraph, it deals with the same problem, kinda.
https://github.com/pyqtgraph/pyqtgraph/blob/develop/pyqtgraph/Qt.py
from pyvista-support.
Nice find, thanks for sharing!
from pyvista-support.
@ezalorpro - I actually cannot get the script you shared above to work... Am I missing something?:
from PySide2 import QtWidgets
import numpy as np
import pyvista as pv
import sys
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None, show=True):
super(MainWindow, self).__init__(parent)
# create the frame
self.frame = QtWidgets.QFrame()
vlayout = QtWidgets.QVBoxLayout()
# add the pyvista interactor object
self.vtk_widget = pv.QtInteractor(self.frame)
vlayout.addWidget(self.vtk_widget)
self.frame.setLayout(vlayout)
self.setCentralWidget(self.frame)
# simple menu to demo functions
mainMenu = self.menuBar()
fileMenu = mainMenu.addMenu('File')
exitButton = QtWidgets.QAction('Exit', self)
exitButton.setShortcut('Ctrl+Q')
exitButton.triggered.connect(self.close)
fileMenu.addAction(exitButton)
# allow adding a sphere
meshMenu = mainMenu.addMenu('Mesh')
self.add_sphere_action = QtWidgets.QAction('Add Sphere', self)
self.add_sphere_action.triggered.connect(self.add_sphere)
meshMenu.addAction(self.add_sphere_action)
if show:
self.show()
def add_sphere(self):
""" add a sphere to the pyqt frame """
sphere = pv.Sphere()
self.vtk_widget.add_mesh(sphere)
self.vtk_widget.reset_camera()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())
Then I get the error:
Traceback (most recent call last):
File "test.py", line 48, in <module>
window = MainWindow()
File "test.py", line 16, in __init__
self.vtk_widget = pv.QtInteractor(self.frame)
File "/Users/bane/Documents/OpenGeoVis/Software/pyvista/pyvista/plotting/qt_plotting.py", line 290, in __init__
QVTKRenderWindowInteractor.__init__(self, parent)
File "/Users/bane/anaconda3/envs/fras/lib/python3.7/site-packages/vtk/qt/QVTKRenderWindowInteractor.py", line 235, in __init__
QGLWidget.__init__(self, parent)
TypeError: arguments did not match any overloaded call:
QGLWidget(parent: QWidget = None, shareWidget: QGLWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'PySide2.QtWidgets.QFrame'
QGLWidget(QGLContext, parent: QWidget = None, shareWidget: QGLWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'PySide2.QtWidgets.QFrame'
QGLWidget(QGLFormat, parent: QWidget = None, shareWidget: QGLWidget = None, flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags()): argument 1 has unexpected type 'PySide2.QtWidgets.QFrame'
Exception ignored in: <function BasePlotter.__del__ at 0x7fcd604de620>
Traceback (most recent call last):
File "/Users/bane/Documents/OpenGeoVis/Software/pyvista/pyvista/plotting/plotting.py", line 3375, in __del__
self.close()
RuntimeError: super-class __init__() of type QtInteractor was never called
from pyvista-support.
I have version 5.13.0
of PyQt5 and version 5.13.0
of PySide2
from pyvista-support.
i am using:
python -> 3.7.3 - 32 bits
pyvista -> 0.21.4
PySide2 -> 5.13.0
VTK -> 8.2.0
No PyQt5 since it is a virtual enviroment, the only thing worth mentioning is that the line 235 of my QVTKRenderWindowInteractor.py is not that one the show the error, so maybe it is the VTK version?
I try the replace PySide2 thing cuz i read this in the QVTKRenderWindowInteractor.py :
Changes by Tobias Hänel, Sep. 2018
Support for PySide2
from pyvista-support.
Ah yep - I had VTK 8.1.2 in that virtual env. VTK 8.2.0 resolves the issue
from pyvista-support.
Related Issues (20)
- create uniform mesh HOT 3
- Change the orientation of a scalar bar's title
- Applying textures on models from .obj files HOT 6
- How to create an Unstructured grid from points and faces HOT 2
- Type of data, plotting with glyphs HOT 3
- Controlling the thickness and orientation of a slice in Pyvista HOT 3
- Controlling the image position in window, without any click
- Mask/Remove Voxels in Air (small intersection with surface) HOT 3
- custom slider parameters
- running pyvista on headless machine with Centos OS HOT 1
- Seismic Horizon with Pyvista HOT 8
- Algorithm in sample function?
- Automatically updates HOT 3
- Slow interaction HOT 1
- read from text HOT 4
- Uniform Grid thresholding question HOT 8
- Take data by an input x,y,x coordinate (csv file) from vtk data file HOT 4
- Program broke when creating a mesh using pv.PolyData() HOT 4
- ATTENTION: Please move questions to PyVista's Discussions HOT 1
- plotter.enable_terrain_style not working for me HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvista-support.