# QVTKOpenGLWidget: simple animation does not work in a repository version of VTK.

**URL:** https://discourse.vtk.org/t/qvtkopenglwidget-simple-animation-does-not-work-in-a-repository-version-of-vtk/988
**Category:** Support
**Created:** [May 19, 2019, 2:42pm UTC](https://discourse.vtk.org/t/qvtkopenglwidget-simple-animation-does-not-work-in-a-repository-version-of-vtk/988 "2019-05-19T14:42:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sdobashi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@sdobashi](https://discourse.vtk.org/u/sdobashi)
#### Post date: [May 19, 2019, 2:42pm UTC](https://discourse.vtk.org/t/qvtkopenglwidget-simple-animation-does-not-work-in-a-repository-version-of-vtk/988/1 "2019-05-19T14:42:37Z")

</div>

Hello everyone,

A simple animation like “rotating cone” (VTK\Examples\Tutorial\Step1\Cxx\Cone.cxx)  
does not properly work in a recent repository version of VTK if I use QVTKOpenGLWidget,  
while it properly works in VTK 8.2.0.

In the code attached below, I tried to rotate a cone by 180 degrees, repeating

```auto
ren->GetActiveCamera()->Azimuth(1);

```

and

```auto
#if VTK_MINOR_VERSION < 90
        qvtk->GetRenderWindow()->Render();
#else
        qvtk->renderWindow()->Render();
#endif

```

In VTK 8.2.0, it works well, but in the recent repository version (Version 8.90.0?), only the first and the last images are displayed. (the intermediate states between 0 and 180 degrees are not displayed.)

Some additional procedures are required in the Version 8.90.0 in order to achieve an expected result like VTK 8.2.0?

I appreciate any help.

Thanks in advance and best regards.

* * *

cone\_rot\_main.cpp [cone\_rot\_main.cpp](https://discourse.vtk.org/uploads/default/original/1X/9e201062d66b92b48e7f1dcdc3cf19bd8d3659b1.cpp) (177 Bytes)

```auto
#include "cone_rot.h"
#include <QApplication>
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
 
    return a.exec();
}

```

cone\_rot.cpp [cone\_rot.cpp](https://discourse.vtk.org/uploads/default/original/1X/dff368b69a1ce99d5a2efc81f0009e384fab07b5.cpp) (1.7 KB)

```auto
#include <vtkSmartPointer.h>
#include <vtkConeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkCamera.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkGenericOpenGLRenderWindow.h>
 
#include <QPushButton>
#include <QVBoxLayout>
#include <QVTKOpenGLWidget.h>
 
#include "cone_rot.h"
 
Widget::Widget(QWidget *parent) : QWidget(parent)
{
    // Push button
    push_button = new QPushButton;
    push_button->setText("Rotate");
 
    // QVTK
    qvtk = new QVTKOpenGLWidget;
 
    // Layout
    layout = new QVBoxLayout;
    layout->addWidget(push_button);
    layout->addWidget(qvtk);
    setLayout(layout);
    resize(400, 300);
 
    // Signal & slot
    connect(push_button, SIGNAL(clicked()), this, SLOT(rotate_cone()));
 
    cone = vtkSmartPointer<vtkConeSource>::New();
    actor = vtkSmartPointer<vtkActor>::New();
    ren = vtkSmartPointer<vtkRenderer>::New();
 
    auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    auto renwin = vtkSmartPointer<vtkGenericOpenGLRenderWindow>::New();
 
    mapper->SetInputConnection(cone->GetOutputPort());
    actor->SetMapper(mapper);
    ren->AddActor(actor);
    renwin->AddRenderer(ren);
 
#if VTK_MINOR_VERSION < 90
    qvtk->SetRenderWindow(renwin);
#else
    qvtk->setRenderWindow(renwin);
#endif
}
 
Widget::~Widget()
{
    delete push_button;
    delete qvtk;
    delete layout;
}
 
void Widget::rotate_cone() const
{
    for (auto i = 0; i < 180; ++i) {
#if VTK_MINOR_VERSION < 90
        qvtk->GetRenderWindow()->Render();
#else
        qvtk->renderWindow()->Render();
#endif
        ren->GetActiveCamera()->Azimuth(1);
    }
}

```

cone\_rot.h [cone\_rot.h](https://discourse.vtk.org/uploads/default/original/1X/00fd755ed6e5f87e51d1ac2bb87e2158dec85b63.h) (610 Bytes)

```auto
#pragma once
 
#include <vtkSmartPointer.h>
#include <vtkConeSource.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
 
#include <QWidget>
 
class QPushButton;
class QVTKOpenGLWidget;
class QVBoxLayout;
 
class Widget : public QWidget
{
    Q_OBJECT
 
public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();
 
private slots:
    void rotate_cone() const;
 
private:
    QPushButton* push_button;
    QVTKOpenGLWidget* qvtk;
    QVBoxLayout* layout;
 
    vtkSmartPointer<vtkConeSource> cone;
    vtkSmartPointer<vtkActor> actor;
    vtkSmartPointer<vtkRenderer> ren;
};

```

CMakeLists.txt [CMakeLists.txt](https://discourse.vtk.org/uploads/default/original/1X/1b145a150a7ff3703e7a3a67275ec066224a3d8a.txt) (607 Bytes)

```auto
cmake_minimum_required(VERSION 3.10)

# Target
set(TARGET_NAME cone_rot)
project(${TARGET_NAME})

# VTK
find_package(VTK REQUIRED)
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
  include(${VTK_USE_FILE})
endif()

# Qt5
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

# Target
set( Srcs ${TARGET_NAME}_main.cpp ${TARGET_NAME}.cpp ${TARGET_NAME}.h)

find_package(Qt5 COMPONENTS Widgets REQUIRED)

add_executable(${TARGET_NAME} ${Srcs})

# Qt5 libraires
target_link_libraries(${TARGET_NAME} Qt5::Widgets)

target_link_libraries(${TARGET_NAME} ${VTK_LIBRARIES})

```

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 19, 2019, 7:13pm UTC](https://discourse.vtk.org/t/qvtkopenglwidget-simple-animation-does-not-work-in-a-repository-version-of-vtk/988/2 "2019-05-19T19:13:36Z")

</div>

You either need to use a Qt timer (instead of the for loop) or call [processEvents](https://doc.qt.io/qt-5/qcoreapplication.html#processEvents) in the for loop to allow any widget updates to happen (to give a chance to the application to process paint events).

---

<div class="post-metadata">

### Author: ![sdobashi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@sdobashi](https://discourse.vtk.org/u/sdobashi)
#### Post date: [May 20, 2019, 1:32am UTC](https://discourse.vtk.org/t/qvtkopenglwidget-simple-animation-does-not-work-in-a-repository-version-of-vtk/988/3 "2019-05-20T01:32:01Z")

</div>

Thank you very much for the prompt and perfect solution!

Simply inserting QCoreApplication::processEvents() did the trick.

```auto
    for (auto i = 0; i < 180; ++i) {
        qvtk->renderWindow()->Render();
        ren->GetActiveCamera()->Azimuth(1);
        QCoreApplication::processEvents();
    }

```
