When embedding VTK qt met VTK widget can’t move, began to directly copy the official case inside vtkScalarBarWidget wording, is shown in the QVTKRenderWindowInteractor abnormalities, cannot interact with the widget.
https://vtk.org/Wiki/VTK/Examples/Python/Widgets/ScalarBarWidget
in writing is as follows:
# create the scalar_bar_widget
scalar_bar_widget = vtk.vtkScalarBarWidget()
scalar_bar_widget.SetInteractor(interactor)
scalar_bar_widget.SetScalarBarActor(scalar_bar)
scalar_bar_widget.On()
Changed to:
# create the scalar_bar_widget
self.scalar_bar_widget = vtk.vtkScalarBarWidget()
self.scalar_bar_widget.SetInteractor(self.iren)
self.scalar_bar_widget.SetScalarBarActor(scalar_bar)
self.scalar_bar_widget.On()
This means that the widget should be prefixed with self when loading with classes.
>
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import sys
import vtk
class MainPage(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.setObjectName("MainWindow")
self.resize(603, 553)
self.centralWidget = QtWidgets.QWidget(self)
self.gridlayout = QtWidgets.QGridLayout(self.centralWidget)
self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
self.gridlayout.addWidget(self.vtkWidget)
self.setCentralWidget(self.centralWidget)
self.ren = vtk.vtkRenderer()
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
# Create source
source = vtk.vtkSphereSource()
source.SetCenter(0, 0, 0)
source.SetRadius(5.0)
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
self.ren.AddActor(actor)
# create the scalar_bar
scalar_bar = vtk.vtkScalarBarActor()
scalar_bar.SetOrientationToHorizontal()
lut = vtk.vtkLookupTable()
lut.Build()
scalar_bar.SetLookupTable(lut)
# create the scalar_bar_widget
self.scalar_bar_widget = vtk.vtkScalarBarWidget()
self.scalar_bar_widget.SetInteractor(self.iren)
self.scalar_bar_widget.SetScalarBarActor(scalar_bar)
self.scalar_bar_widget.On()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainPage()
window.show()
window.iren.Initialize()
sys.exit(app.exec_())
Read More:
- Python 3 install pyqt5
- Vtkrenderwindow and vtkrenderwindow actor
- Python – writing visual interface (Python + pycharm + pyqt)
- Howto Install and Configure VTK on Ubuntu
- Installing PyQt4 in Windows + Python 3.6
- Error in compiling pcl1.9.1: “class vtkdatasetmapper” has no member named “immediatemode rendering off”
- [debug notes] pointer error when STD:: vector is used in VTK “access conflict when reading location XXX”
- Spring boot can’t scan XML (invalid bound statement (not found))
- The app failed to start because there is no Qt platform to initialize
- Using vtk8.1 in qcreator
- Springboot error: property ‘sqlsessionfactory’ or ‘sqlsessiontemplate’ are required error details
- VTK + QT + vs compilation and installation configuration
- Compile QT source code error causes and Solutions
- Result Maps collection already contains value for com.xxx.xxxMapper . baseresultmap problem solving
- Package python3.1 + PyQt4 into exe
- Related configuration of mybatis project
- Index error: invalid index to scalar variable
- Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://xxx.cn’) does n
- Methods of modifying index and columns names by dataframe in pandas
- [Fixed] Error:(3) Error retrieving parent for item: No resource found that matches the given name ‘android’