[vtkusers] PyQt VTK on OSX only show up in the lower left quarter of the display window
Bill Q
bill.q.hdp at gmail.com
Mon Mar 6 03:06:09 EST 2017
Hi All,
I encountered a wired problem while using Python 2.7, PyQT5.6 and VTK7.1 on
OSX. The render window only take the lower left quarter of the entire
display window. While I tried the same code on windows with same versions
of libs, it worked fine. The code is as following:
from PyQt5.QtWidgets import *import vtkfrom
vtk.qt.QVTKRenderWindowInteractor import
QVTKRenderWindowInteractorimport sys
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(603, 553)
self.centralWidget = QWidget(MainWindow)
self.gridlayout = QGridLayout(self.centralWidget)
self.vtkWidget = QVTKRenderWindowInteractor(self.centralWidget)
self.gridlayout.addWidget(self.vtkWidget, 0, 0, 100, 100)
self.buttonLeft = QPushButton("Left")
self.gridlayout.addWidget(self.buttonLeft, 96,48,1,1)
self.buttonRight = QPushButton("Right")
self.gridlayout.addWidget(self.buttonRight, 96,52,1,1)
self.buttonUp= QPushButton("Up")
self.gridlayout.addWidget(self.buttonUp, 94,50,1,1)
self.buttonDown = QPushButton("Down")
self.gridlayout.addWidget(self.buttonDown, 98,50,1,1)
self.buttonFire = QPushButton("Fire Torpedo")
self.gridlayout.addWidget(self.buttonFire, 95,50,3,1)
MainWindow.setCentralWidget(self.centralWidget)
class SimpleView(QMainWindow):
def __init__(self, parent = None):
QMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ren = vtk.vtkRenderer()
self.ui.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.ui.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)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = SimpleView()
window.show()
window.iren.Initialize() # Need this line to actually show the
render inside Qt
sys.exit(app.exec_())
You may find the screen captures from SO:
http://stackoverflow.com/questions/42620354/pyqt-vtk-on-osx-only-show-up-in-the-lower-left-of-the-display-window
Many thanks.
Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170306/41c84587/attachment.html>
More information about the vtkusers
mailing list