<div dir="ltr">Hello,<br><br>There is a bug in QVTKWidget on OSX with a retina display, when build with Qt5. Any QVTKWidget will display only the bottom left quarter, like this :<div><img src="http://s4.postimg.org/qptf9pni5/fail.png" style="margin-right: 0px;" width="202" height="217"><br></div><div>Here is a very simple program that reproduce the bug :<br></div><div><div><br></div><div>----------------------------------------------------------------------------------------------<br></div><div><div><i>#include <QApplication></i></div><div><i>#include <vtkActor.h></i></div><div><i>#include <vtkPolyDataMapper.h></i></div><div><i>#include <vtkSmartPointer.h></i></div><div><i>#include <vtkSphereSource.h></i></div><div><i>#include <vtkRenderer.h></i></div><div><i>#include <vtkRenderWindow.h></i></div><div><i>#include <QVTKWidget.h></i></div><div><i><br></i></div><div><i>#define VTK_NEW(type, instance) \</i></div><div><i>  vtkSmartPointer<type> instance = vtkSmartPointer<type>::New();</i></div><div><i><br></i></div><div><i>int main(int argc, char** argv)</i></div><div><i>{</i></div><div><i>  QApplication app(argc, argv);</i></div><div><i>  QVTKWidget widget;</i></div><div><i><br></i></div><div><i>  VTK_NEW(vtkSphereSource, sphereSource);</i></div><div><i>  VTK_NEW(vtkPolyDataMapper, sphereMapper);</i></div><div><i>  VTK_NEW(vtkActor, sphereActor);</i></div><div><i>  VTK_NEW(vtkRenderWindow, renderWindow);</i></div><div><i>  VTK_NEW(vtkRenderer, renderer);</i></div><div><i><br></i></div><div><i>  sphereMapper->SetInputConnection(sphereSource->GetOutputPort());</i></div><div><i>  sphereActor->SetMapper(sphereMapper);</i></div><div><i>  renderWindow->AddRenderer(renderer);</i></div><div><i>  renderer->SetBackground(0.1, 0.3, 0.4);</i><i><br></i></div><div><i>  renderer->AddActor(sphereActor);</i></div><div><i>  widget.SetRenderWindow(renderWindow);</i></div><div><i>  widget.resize(256,256);</i></div><div><i>  widget.show();</i></div><div><i> </i></div><div><i>  app.exec();</i></div><div><i> </i></div><div><i>  return 0;</i></div><div><i>}</i></div><div>----------------------------------------------------------------------------------------------<br></div><br>and the CMakeLists.txt :</div><div>----------------------------------------------------------------------------------------------</div><div><div><i>cmake_minimum_required(VERSION 3.1)</i></div><div><i>if(POLICY CMP0053)</i></div><div><i>  cmake_policy(SET CMP0053 NEW)</i></div><div><i>endif()</i></div><div><i>project(QtImageViewer)</i></div><div><i><br></i></div><div><i>find_package(VTK COMPONENTS vtkGUISupportQt )</i></div><div><i>include(${VTK_USE_FILE})</i></div><div><i>find_package(Qt5Core REQUIRED QUIET)</i></div><div><i><br></i></div><div><i>add_executable(qtimageviewer </i><i>main.cxx</i><i>)</i></div><div><i>qt5_use_modules(qtimageviewer Core Gui Widgets)</i></div><div><i>target_link_libraries(qtimageviewer ${VTK_LIBRARIES})</i></div>----------------------------------------------------------------------------------------------</div><div><br></div><div>To enable retina on a normal display, use this :<br><a href="http://cocoamanifest.net/articles/2013/01/turn-on-hidpi-retina-mode-on-an-ordinary-mac.html" target="_blank">http://cocoamanifest.net/articles/2013/01/turn-on-hidpi-retina-mode-on-an-ordinary-mac.html</a></div><div>----------------------------------------------------------------------------------------------</div><div><br></div><div>Now to get back to a normal behavior, like it was with Qt4, one need to call :<br><b>setWantsBestResolutionOpenGLSurface:NO </b>on the<b> NSView </b>of the QVTKWidget !<br><br>Here is an example on how to solve the problem on the small example above :<br><br></div><div>main.cxx</div><div>----------------------------------------------------------------------------------------------</div><div><div><i>#include <QApplication></i></div><div><i>#include <vtkActor.h></i></div><div><i>#include <vtkPolyDataMapper.h></i></div><div><i>#include <vtkSmartPointer.h></i></div><div><i>#include <vtkSphereSource.h></i></div><div><i>#include <vtkRenderer.h></i></div><div><i>#include <vtkRenderWindow.h></i></div><div><i>#include <QVTKWidget.h></i></div><div><i><br></i></div><div><i>#define VTK_NEW(type, instance) \</i></div><div><i>  vtkSmartPointer<type> instance = vtkSmartPointer<type>::New();</i></div><div><i><br></i></div><div><i><b>#ifdef Q_OS_OSX</b></i></div><div><i><b>#include "osxHelper.h"</b></i></div><div><i><b>#endif</b></i></div><div><i><br></i></div><div><i>int main(int argc, char** argv)</i></div><div><i>{</i></div><div><i>  QApplication app(argc, argv);</i></div><div><i>  QVTKWidget widget;</i></div><div><i><b>#ifdef Q_OS_OSX</b></i></div><div><i><b>  disableGLHiDPI(widget.winId());</b></i></div><div><i><b>#endif</b></i></div><div><i><br></i></div><div><i>  VTK_NEW(vtkSphereSource, sphereSource);</i></div><div><i>  VTK_NEW(vtkPolyDataMapper, sphereMapper);</i></div><div><i>  VTK_NEW(vtkActor, sphereActor);</i></div><div><i>  VTK_NEW(vtkRenderWindow, renderWindow);</i></div><div><i>  VTK_NEW(vtkRenderer, renderer);</i></div><div><i><br></i></div><div><i>  sphereMapper->SetInputConnection(sphereSource->GetOutputPort());</i></div><div><i>  sphereActor->SetMapper(sphereMapper);</i></div><div><i>  renderWindow->AddRenderer(renderer);</i></div><div><i>  renderer->SetBackground(0.1, 0.3, 0.4);</i></div><div><i>  renderer->AddActor(sphereActor);</i></div><div><i>  widget.SetRenderWindow(renderWindow);</i></div><div><i>  widget.resize(256,256);</i></div><div><i>  widget.show();</i></div><div><i> </i></div><div><i>  app.exec();</i></div><div><i> </i></div><div><i>  return 0;</i></div><div><i>}</i></div><div><br></div></div><div>----------------------------------------------------------------------------------------------</div><div><br></div><div>osxHelper.h</div><div>----------------------------------------------------------------------------------------------<br></div><div><div><i>#ifndef _OSX_HELPER_</i></div><div><i>#define _OSX_HELPER_</i></div><div><i>void disableGLHiDPI( long a_id );</i></div><div><i>#endif</i></div></div><div>----------------------------------------------------------------------------------------------<br></div><div><br></div><div>osxHelper.mm</div><div>----------------------------------------------------------------------------------------------<br></div><div><div><i>#include <Cocoa/Cocoa.h></i></div><div><i>#include "osxHelper.h"</i></div><div><i><br></i></div><div><i>void disableGLHiDPI( long a_id ){</i></div><div><i><span class="" style="white-space:pre">      </span>NSView* view = reinterpret_cast<NSView*>( a_id );</i></div><div><i><span class="" style="white-space:pre"> </span>[view setWantsBestResolutionOpenGLSurface:NO];</i></div><div><i>}</i></div></div><div>----------------------------------------------------------------------------------------------<br></div><div><br></div><div>CMakeLists.txt</div><div>----------------------------------------------------------------------------------------------<br></div><div><div><i>cmake_minimum_required(VERSION 3.1)</i></div><div><i>if(POLICY CMP0053)</i></div><div><i>  cmake_policy(SET CMP0053 NEW)</i></div><div><i>endif()</i></div><div><i>project(QtImageViewer)</i></div><div><i><br></i></div><div><i>find_package(VTK COMPONENTS vtkGUISupportQt )</i></div><div><i>include(${VTK_USE_FILE})</i></div><div><i>find_package(Qt5Core REQUIRED QUIET)</i></div><div><i><b>find_library( LIB_COCOA cocoa )</b></i></div><div><br></div><div><i>add_executable(qtimageviewer </i><i>main.cxx <b>osxHelper.mm</b></i><i>)</i></div><div><i>qt5_use_modules(qtimageviewer Core Gui Widgets)</i></div><div><i>target_link_libraries(qtimageviewer ${VTK_LIBRARIES})</i></div></div><div>----------------------------------------------------------------------------------------------<br></div><div>And there you go, problem solved ...</div><div><br></div><div>I hope this is useful to others, maybe this can be integrated in the upcoming 6.2 release !<br><br><div>Have a nice day !!</div><div><br></div><div>Simon</div><br>Note on the topic if one day someone want to really support HiDPI for retina displays :<br></div><div>The bug was probably introduced by this commit in Qt :<br><a href="https://qt.gitorious.org/qt/qtbase/commit/1caa0c023f4fa60446094e53f22ee79771130e2f" target="_blank">https://qt.gitorious.org/qt/qtbase/commit/1caa0c023f4fa60446094e53f22ee79771130e2f</a></div><div>Documentation :<br><a href="https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html" target="_blank">https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html</a><br clear="all"><div><br></div><div><br></div>-- <br><div><div dir="ltr"><div>------------------------------------------------------------------<br>Simon Esneault<div>Rennes, France<br>------------------------------------------------------------------</div></div></div></div>
</div></div></div>