problem 1
QVTKOpenGLWidget requires a
vtkGenericOpenGLRenderWindow
.
vtkCocoaRenderWindow
is not supported.
QVTKOpenGLWidget 对应使用的renderWindow是 vtkGenericOpenGLRenderWindow
problem 2
VTK is designed to work with OpenGL version 3.2 but it appears it has been given a context that does not support 3.2. VTK will run in a compatibility mode designed to work with earlier versions of OpenGL but some features may not work.
需要设置surfaceFormat
// needed to ensure appropriate OpenGL context is created for VTK rendering.
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
problem 3
cmake设置应用图标
启动前的app图标设置:
# NOTE: Don't include the path in MACOSX_BUNDLE_ICON_FILE -- this is
# the property added to Info.plist
# <key>CFBundleIconFile</key>
# <string>logo</string>
set(MACOSX_BUNDLE_ICON_FILE logo)
# And this part tells CMake where to find and install the file itself
set(myApp_ICON ${CMAKE_CURRENT_SOURCE_DIR}/Images/logo.icns)
# set_source_files_properties would create Resources folder to store icns
# The folder is at same path where Info.plist located
set_source_files_properties(${myApp_ICON} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
add_executable(
${PROJECT_NAME}
MACOSX_BUNDLE
${SourceFiles}
${HeaderFiles}
${ResourceFiles}
${UISrcs}
${myApp_ICON} # Add icon file to see in IDE.
)
程序运行中的图标设置:
QApplication a(argc, argv);
OpenFileDialog::getInstance()->show();
#ifdef Q_OS_MAC
QString iconPath = QCoreApplication::applicationDirPath();
iconPath = iconPath + "/Images/logo.icns";
a.setWindowIcon( QIcon( iconPath ) );
#elif Q_OS_WIN
#endif
problem 4
如何在ui文件中添加QVtkOpenGLWidget ?
在ui文件的文本编辑模式下增添如下代码:
</widget>
<customwidgets>
<customwidget>
<class>QVTKOpenGLWidget</class>
<extends>QWidget</extends>
<header>QVTKOpenGLWidget.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
再增添
<item>
<widget class="QVTKOpenGLWidget" name="qvtkWidget"/>
</item>
到widget 标签块中。