我是设计GUI和Python的新手
我试图在用QTDesign制作的简单GUI中显示渲染,但是没有正确显示。
渲染有效,但我希望渲染小部件位于主内部 窗口(或任何其他窗口小部件?)但不起作用。
有人知道怎么做吗?
问候! 全型
用户界面:
from PySide import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(455, 380)
MainWindow.setMinimumSize(QtCore.QSize(455, 380))
MainWindow.setMaximumSize(QtCore.QSize(455, 380))
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtGui.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(365, 340, 75, 23))
self.pushButton.setObjectName("pushButton")
self.frame = QtGui.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(20, 20, 416, 306))
self.frame.setFrameShape(QtGui.QFrame.StyledPanel)
self.frame.setFrameShadow(QtGui.QFrame.Raised)
self.frame.setObjectName("frame")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "PushButton", None, QtGui.QApplication.UnicodeUTF8))
主程序......
from Prueba_Viewer import Ui_MainWindow
import vtk
from PySide import QtGui
from PySide import QtCore
import sys
import os
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
class MaxWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
#self.ui = Ui_main()
#self.ui.setupUi(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.meshDisplayWidget = QVTKRenderWindowInteractor(self.ui.frame)
self.ui.meshDisplayWidget.Initialize()
#Set actors and mappers, then instead of creating a renderwindowinteractor,
#use the self.ui.meshDisplayWidget to display the mesh. Also define picker, and
#set data source (for code about displaying a mesh from coordinates, as
#an unstructured grid.
cone = vtk.vtkConeSource()
cone.SetResolution(28)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInput(cone.GetOutput())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
ren = vtk.vtkRenderer()
ren.AddActor(coneActor)
ren.ResetCamera()
cam1 = ren.GetActiveCamera()
self.ui.meshDisplayWidget.GetRenderWindow().AddRenderer(ren)
#self.ui.meshDisplayWidget.SetPicker(picker_point)
self.ui.meshDisplayWidget.show()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
maxwin = MaxWindow()
Max_Window = maxwin
maxwin.show()
exit_code = app.exec_()
sys.exit(exit_code)
答案 0 :(得分:2)
你看到这个例子了吗?它适用于我为PyQt交换PySide。 http://www.vtk.org/Wiki/VTK/Examples/Python/Widgets/EmbedPyQt
答案 1 :(得分:1)
要在Widget内部渲染,请使用QVTKRenderWindowInteractor类。 首先,进入这里:
你可以做两件事。
第一个选项:
一个。像往常一样创建Qt窗口。
湾创建一个QVTKRenderWindowInteractor实例,并将其父级设置为要包含它的小部件/窗口。
self.myViewer= QVTKRenderWindowInteractor(self.parentWidget)
QVTKRenderWindowInteractor是vtkRenderWindowInteractor的包装器,你可以得到这样的渲染窗口:
self.myViewer.GetRenderWindow()
第二个选项:
您可以使用QtDesigner将您的小部件宣传为QVTKRenderWindowInteractor