4
votes

I have a widget that inherits from QVTKWidget.

class MyWidget : public QVTKWidget
{
    ...
}

This widget is instantiated from an automatically generated header ui_MainWindow.h file using QT Designer and QT Interface Compiler.

...
myWidget = new MyWidget(centralWidget);
myWidget->setObjectName(QString::...);
...

In the main window, which inherits from QMainWindow, setupUi is called, so myWidget is initialized.

In the constructor of MyWidget the vtkRenderWindow and vtRenderer are initialized.

MyWidget::MyWidget(QWidget *parent) : QVTKWidget(parent)
{
    ...

    renderWindow = vtkRenderWindow::New();
    renderer = vtkRenderer::New();
    renderer->SetBackground(72.0 / 255.0, ...

    renderWindow->AddRenderer(renderer);
    this->SetRenderWindow(renderWindow);

    QVTKInteractor * iren = this->GetInteractor();
    renderWindow->SetInteractor(iren);

    camera = vtkCamera::New();
    camera->SetPosition(...
    camera->SetFocalPoint(...
    camera->SetViewUp(...

    renderer->SetActiveCamera(camera);

    draw(renderer); // Custom draw function, adds actors etc.

    renderer->Render();
    renderWindow->Render();
    iren->Render();
}

However, nothing is shown until I click and move (MouseMove). Then, my scene appears. I've tried changing the order of the calls as well as adding additional Render calls in timers, but to no avail.

Can someone point me to a good way to ensure that this widget, instantiated in this way, is rendered after the constructor has come to pass?

Note: I have no own Mouse-Move implementation. Mouse motion seems to have the right effect, i.e. the scene is rotated slightly according to my mouse move when it is first rendered.

1

1 Answers

0
votes

Try calling:

iRen->ReInitialize()

as the very last step in your code. Whenever I want to ensure that the render window interactor is up to date, I call reinitialize on it. Let me know if it works.