[vtkusers] how to change my vtk in my pyqt

Mitto 376901333 at qq.com
Sun Aug 17 06:26:01 EDT 2014


hello
i am facing an problem
code like this :
when i click the button  i want to change the vtk


from PyQt4 import QtCore, QtGui
from PyQt4.Qt import *
from PyQt4.QtGui import QApplication
import vtk
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import sys

try:
        _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
        def _fromUtf8(s):
                return s

try:
        _encoding = QtGui.QApplication.UnicodeUTF8
        def _translate(context, text, disambig):
                return QtGui.QApplication.translate(context, text, disambig,
_encoding)
except AttributeError:
        def _translate(context, text, disambig):
                return QtGui.QApplication.translate(context, text, disambig)        


class Ui_MainWindow(object):
        def setupUi(self, MainWindow):
                MainWindow.setObjectName(_fromUtf8("MainWindow"))
                MainWindow.resize(802, 621)
                self.centralwidget = QtGui.QWidget(MainWindow)
                self.centralwidget.setObjectName(_fromUtf8("centralwidget"))                
                MainWindow.setCentralWidget(self.centralwidget)
                self.vtkWidget =
QVTKRenderWindowInteractor(self.centralwidget)
                self.Start= QtGui.QPushButton(self.centralwidget)
                self.Start.setGeometry(QtCore.QRect(650, 370, 98, 27))
                self.Start.setObjectName(_fromUtf8("START"))  
               
               
               
                QtCore.QObject.connect(self.Start,
QtCore.SIGNAL(_fromUtf8("clicked()")), self.Change)
             
             
        def Change(self):
                print("start change")
               
                       

       
         
   



   
class SimpleView(QtGui.QMainWindow):
 
        def __init__(self, parent = None):
                QtGui.QMainWindow.__init__(self, parent)
                self.ui = Ui_MainWindow()
                self.ui.setupUi(self)
                self.ren = vtk.vtkRenderer()
                self.ui.vtkWidget.resize(370,340)
                self.ui.vtkWidget.move(20,20)
               
                self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
                self.iren =
self.ui.vtkWidget.GetRenderWindow().GetInteractor()
             
               
                # Create source
                filename="filename"
                reader = vtk.vtkPolyDataReader()
                reader.SetFileName(filename)        
         
                # Create a mapper
                mapper = vtk.vtkPolyDataMapper()
                mapper.SetInputConnection(reader.GetOutputPort())
         
                # Create an actor
                actor = vtk.vtkActor()
                actor.GetProperty().SetColor(0,1,0)    
                actor.SetMapper(mapper)
                self.ren.AddActor(actor)
               
                   
if __name__ == "__main__":
 
        app = QApplication(sys.argv)
        window = SimpleView()
        window.show()
        window.iren.Initialize()
        sys.exit(app.exec_())





--
View this message in context: http://vtk.1045678.n5.nabble.com/how-to-change-my-vtk-in-my-pyqt-tp5728238.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list