QVTKOpenGLWidget with vtkBalloonWidget leads to black window when focus is changing
Moving from the old QVTKWidget to the new QVTKOpenGLWidget, I noticed the bug, when a vtkBalloonWidget was added to the QVTKInteractor. When QVTKOpenGLWidget object loses the focus (and in some other cases), then it becomes black (when you move mouse over it, then all is OK again).
Video is here: https://youtu.be/aRlfiZpFFqE
The code to reproduce the bug:
#include <QApplication>
#include <QSurfaceFormat>
#include <QVTKOpenGLWidget.h>
#include <vtkRenderer.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkBalloonWidget.h>
#include <vtkSphereSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingOpenGL2)
int main(int argc, char *argv[])
{
QSurfaceFormat::setDefaultFormat(QVTKOpenGLWidget::defaultFormat());
QApplication a(argc, argv);
vtkNew<vtkRenderer> mRenderer;
mRenderer->SetBackground(.3, .6, .3);
vtkNew<vtkGenericOpenGLRenderWindow> mRenderWindow;
mRenderWindow->AddRenderer(mRenderer.Get());
vtkNew<QVTKInteractor> mRenderWindowInteractor;
mRenderWindowInteractor->SetRenderWindow(mRenderWindow.Get());
vtkNew<vtkBalloonWidget> mBalloonWidget;
mBalloonWidget->SetInteractor(mRenderWindowInteractor.Get());
mBalloonWidget->EnabledOn(); // remove this line to fix the bug (but we need it for balloons)
// Add a sphere for beauty (but we can get the bug without any actor too)
vtkNew<vtkSphereSource> sphere;
sphere->SetCenter(0.0, 0.0, 0.0);
sphere->SetRadius(5.0);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(sphere->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
mRenderer->AddActor(actor);
QVTKOpenGLWidget vtkOpenGlWidget;
vtkOpenGlWidget.SetRenderWindow(mRenderWindow.Get());
vtkOpenGlWidget.show();
mRenderWindow->Render();
return a.exec();
}
All works good without this line:
mBalloonWidget->EnabledOn();
And there are no problems with old QVTKWidget, but there is this bug with new QVTKOpenGLWidget and balloons enabled.
Current temporary ugly workaround is: inherit own class from vtkBalloonWidget and override next method:
int SubclassHoverAction() override {
auto result = Superclass::SubclassHoverAction();
Render();
return result;
}
Compiler is MSVC++ 2017 32 bit, VTK 8.1.0, Qt 5.10.1
Tested on Win 7 SP1 x64, Win 10 x64 (AMD Radeon HD 7800 Series)