qt_window3.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import sys
  2. from PyQt5 import Qt
  3. from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
  4. from vedo import Plotter, Cone
  5. class MainWindow(Qt.QMainWindow):
  6. def __init__(self, parent=None):
  7. Qt.QMainWindow.__init__(self, parent)
  8. self.frame = Qt.QFrame()
  9. self.layout = Qt.QVBoxLayout()
  10. self.widget = QVTKRenderWindowInteractor(self.frame)
  11. # Create renderer and add the vedo objects and callbacks
  12. self.plt = Plotter(N=2, axes=1, qt_widget=self.widget)
  13. self.id1 = self.plt.add_callback("mouse click", self.onMouseClick)
  14. self.id2 = self.plt.add_callback("key press", self.onKeypress)
  15. cone1 = Cone().rotate_x(20)
  16. cone2 = Cone().rotate_x(40).c("blue5")
  17. self.plt.at(0).show(cone1)
  18. self.plt.at(1).show(cone2)
  19. # Set up the rest of the Qt window
  20. button = Qt.QPushButton("My Button makes the cone red")
  21. button.setToolTip("This is an example button")
  22. button.clicked.connect(self.onClick)
  23. self.layout.addWidget(self.widget)
  24. self.layout.addWidget(button)
  25. self.frame.setLayout(self.layout)
  26. self.setCentralWidget(self.frame)
  27. self.show() # NB: qt, not a Plotter method
  28. def onMouseClick(self, evt):
  29. print("mouse clicked")
  30. def onKeypress(self, evt):
  31. print("key pressed:", evt.keypress)
  32. @Qt.pyqtSlot()
  33. def onClick(self):
  34. self.plt.objects[0].color("red5").rotate_z(40)
  35. self.plt.render()
  36. def onClose(self):
  37. self.widget.close()
  38. if __name__ == "__main__":
  39. app = Qt.QApplication(sys.argv)
  40. window = MainWindow()
  41. app.aboutToQuit.connect(window.onClose)
  42. app.exec_()