Comments (9)
Hey, I would recommend reviewing #67 . I think you're having the same issue. If so, sorry, it's absolutely my fault.
from pyvistaqt.
thank you for the fast response, so i used the pip install command provided in the issue, but my version seem not be changed, and there fore the error still occurs...
from pyvistaqt.
I'll look into this (hopefully) tomorrow and see if I can figure out what's going on.
from pyvistaqt.
@lmarschall, change your code to the following and you should be all good to go:
import os
import sys
os.environ["QT_API"] = "pyside2"
# note import `qtpy` objects instead of `PySide2` objects
from qtpy import QtWidgets
from qtpy.QtWidgets import QMainWindow
# note placement of `import vtkmodules.qt after importing qtpy stuff
import vtkmodules.qt
import numpy as np
import pyvista as pv
from pyvistaqt import QtInteractor
class MainWindow(QMainWindow):
def __init__(self, parent=None, show=True):
QtWidgets.QMainWindow.__init__(self, parent)
# create the frame
self.frame = QtWidgets.QFrame()
vlayout = QtWidgets.QVBoxLayout()
# add the pyvista interactor object
self.plotter = QtInteractor(self.frame)
vlayout.addWidget(self.plotter.interactor)
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.plotter.add_mesh(sphere, show_edges=True)
self.plotter.reset_camera()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())
You'll see that the biggest difference is where I import vtkmodules.qt
. This must be done after you have imported the qtpy
stuff. This is because qtpy
performs some really crazy stuff for making sure that everything is set up properly for the Qt bindings that you want to use. When you do this:
import vtkmodules.qt
os.environ["QT_API"] = "pyside2"
from qtpy import QtWidgets
from qtpy.QtWidgets import QMainWindow
...
you don't give qtpy
time to setup the Qt bindings for PySide2
properly. Instead, you have handed that task to vtkmodules
, which obviously has made assumptions about the Qt bindings that don't agree with what you are trying to do. For example, note that this works:
import vtkmodules.qt
os.environ["QT_API"] = "pyqt5"
from qtpy import QtWidgets
from qtpy.QtWidgets import QMainWindow
meaning that vtkmodules
assumes pyqt5
as its default Qt Bindings, not PySide2
...
The other really important thing to note is that I don't import PySide2
directly. Instead, I import qtpy
objects. I may be completely wrong, but one of the benefits of using qtpy
is that end users could decide to use pyqt5
or pyside2
at any point just by changing the QT_API
environment variable... it's up to them. In this case, you are the end user. When you import PySide2
objects you circumvent qtpy
's setup process, and make it impossible for end users to use qtpy
to its fullest. I may be completely wrong here - I'm not a GUI developer nor a hardcore Qt user - but I think you should use the qtpy
objects instead.
I hope this helps. Please let me know if you have any other questions, or if things are still not working for you.
from pyvistaqt.
hey nicobako,
i took your code and executed it with the following environment, unfortunately there's another error now :(
my environment:
python: 3.6.7
pyside2: 5.13.2
pyqt: 5.12.3
pyvista: 0.27.2
pyvistaqt: 0.2.0
qt: 5.12.9
qtpy: 1.9.0
my current error:
# add the pyvista interactor object
self.plotter = QtInteractor(self.frame)
QtInteractor cannot be converted to PyQt5.QtCore.QObject in this context
from pyvistaqt.
Your error message says it's trying to convert it to a pyqt5 object. Either you're not running the code as written, or you still have not pip installed the master branch of pyvistaqt. The qtpy functionality is currently only available from the master branch of the GitHub repository. Try uninstalling pyvistaqt, then reinstalling it from the master branch following the directions in #67.
from pyvistaqt.
It works!
Sorry for the last error, that was me getting confused with all my testing environments. Finally i can proceed, thank you so much!
Maybe one last question, is there a plan to integrate qml view support into pyvistaqt?
from pyvistaqt.
I don't know anything about qml view... That's a question for the core developpers of pyvistaqt.
from pyvistaqt.
@lmarschall , do you feel comfortable closing this issue? Is your initial question resolved? If so, you can go ahead and close it yourself. Thanks!
from pyvistaqt.
Related Issues (20)
- only one of the subplots work on 4k monitor
- Online documentation not up to date HOT 1
- Lingering references prevent garbage collection
- Segmentation fault on Mac with PyQt5 HOT 2
- Race condition: BackgroundPlotter has no attribute named image HOT 3
- Running pyvistaqt project in Github Action HOT 2
- Inconsistent plotting results with PyVistaQT versus Jupyter (Trame) backends HOT 3
- Issue using pyvistaqt QtInteractor on Windows 10
- MAINT: Deploy docs HOT 7
- solicitud para agregar característica, para guardar los modelos en formato obj
- Stage release for PyVista 0.40 HOT 3
- Update GC testing fixture
- MAINT: Remove Azure
- Make the canvas background transparent HOT 1
- X Error of failed request: BadWindow (invalid Window parameter) HOT 3
- Border glitch during resize HOT 6
- macOS `pvqt.BackgroundPlotter` never opens window HOT 1
- DOC: MultiPlotter vs BackgroundPlotter
- no mouse interactivity with BackgroundPlotter HOT 1
- Consider adding `.git_archival.txt` to include version number in git archive
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 pyvistaqt.