[vtkusers] VTK integration in PyQt (wrong layout)
Sankhesh Jhaveri
sankhesh.jhaveri at kitware.com
Wed May 9 08:19:37 EDT 2018
Hi,
Could you please share a screenshot of what you’re seeing and what you
expect to see?
Thanks,
Sankhesh
On Wed, May 9, 2018 at 6:17 AM mafiaskafia <tsilveira1993 at gmail.com> wrote:
> I need to create a simple QT application that allows the user to view
> meshes
> using VTK. So basically the program is a window with a frame and a button
> (for now). My layout is such that the button must fill half the length of
> the window, and the frame (that'll display the mesh) will fill the other
> half. For
> experimentation i tried the 3D ball shown here:
>
> https://stackoverflow.com/questions/48105646/embedding-vtk-object-in-pyqt5-window
>
> Note: This is different the example above because i just want part of the
> window to be filled by the VTK widget, instead of the whole window.
>
> Here's my code for foo.py:
>
> from PyQt5 import QtCore, QtGui, QtWidgets
>
> class Ui_MainWindow(object):
> def setupUi(self, MainWindow):
> MainWindow.setObjectName("MainWindow")
> MainWindow.resize(743, 430)
> self.centralwidget = QtWidgets.QWidget(MainWindow)
> self.centralwidget.setObjectName("centralwidget")
> self.horizontalLayout =
> QtWidgets.QHBoxLayout(self.centralwidget)
> self.horizontalLayout.setObjectName("horizontalLayout")
> self.pushButton = QtWidgets.QPushButton(self.centralwidget)
> self.pushButton.setObjectName("pushButton")
> self.horizontalLayout.addWidget(self.pushButton)
> self.frame = QtWidgets.QFrame(self.centralwidget)
> self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
> self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
> self.frame.setObjectName("frame")
> self.horizontalLayout.addWidget(self.frame)
> MainWindow.setCentralWidget(self.centralwidget)
>
>
> self.retranslateUi(MainWindow)
> QtCore.QMetaObject.connectSlotsByName(MainWindow)
>
> def retranslateUi(self, MainWindow):
> _translate = QtCore.QCoreApplication.translate
> MainWindow.setWindowTitle(_translate("MainWindow",
> "MainWindow"))
> self.pushButton.setText(_translate("MainWindow", "PushButton"))
>
> And here is my code for init.py:
>
> import vtk
> import sys
> from PyQt5 import QtCore, QtGui
> from vtk.qt.QVTKRenderWindowInteractor import
> QVTKRenderWindowInteractor
> from PyQt5.QtWidgets import QMainWindow, QApplication, QDialog,
> QFileDialog
> from foo import Ui_MainWindow
> from PyQt5 import Qt
>
> class MainWindow(QMainWindow, Ui_MainWindow):
> def __init__(self, parent=None):
> super(MainWindow, self).__init__(parent)
> self.setupUi(self)
> self.pushButton.clicked.connect(self.OpenVTK)
>
> def OpenVTK(self):
>
> self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
> self.vl = Qt.QVBoxLayout() #I think the mistake might be here..
> self.vl.addWidget(self.vtkWidget)
>
> 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)
>
> self.ren.ResetCamera()
>
> self.frame.setLayout(self.vl)
> self.setCentralWidget(self.frame)
>
> self.show()
> self.iren.Initialize()
> self.iren.Start()
>
> if __name__ == "__main__":
> app = QApplication(sys.argv)
> window = MainWindow()
> window.show()
> sys.exit(app.exec_())
>
> I would be very appreciated if someone could help me out. Thanks in
> advance!
>
>
>
>
>
> --
> Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://vtk.org/mailman/listinfo/vtkusers
>
--
Sankhesh Jhaveri *Sr. Research & Development Engineer* | Kitware
<http://www.kitware.com/> | (518) 881-4417
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180509/ac4ab8d3/attachment.html>
More information about the vtkusers
mailing list