[vtkusers] Repainting problem with QVTKWidget

Wu Ruoyun MRYWu at ntu.edu.sg
Wed Apr 20 05:45:01 EDT 2005


Dear All,

The painting problem mentioned in my previous email could be solved by
modifying the original paintEvent() method as below. Any comments?

Best Wishes!
Ruoyun

void QVTKWidget::paintEvent(QPaintEvent* event)
{
  if (!this->cachedImageCleanFlag)
    {
      vtkRenderWindowInteractor* iren = NULL;
      if(this->mRenWin)
        iren = this->mRenWin->GetInteractor();

      if(!iren || !iren->GetEnabled())
        return;

      iren->Render();
    }

  QPainter painter(this);
  painter.eraseRect( event->rect() );
  painter.drawPixmap(0, 0, this->cachedImage);
}

-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On
Behalf Of Wu Ruoyun
Sent: Wednesday, April 20, 2005 4:01 PM
To: vtkusers at vtk.org
Subject: [vtkusers] Repainting problem with QVTKWidget

Dear All,

I am working with QVTKWidget with Qt 4.0 Beta2 and VTK CVS version,
Windows 2K, Visual Studio C++ 6.

The example of QVTKWidget called "ImageViewer" runs well. However, I got
repainting problem if I put the QVTKWidget as the central widget of a
QMainWindow. The following is the codes. Any mistake in my code or the
QVTKWidget still need some touch up?

Best Wishes!
Ruoyun

#include <QApplication.h>
#include <QMainWindow.h>
#include <QPushButton>
#include <QToolBar.h>
#include <QMenuBar.h>
#include <QMenu.h>

#include <vtkImageViewer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPNGReader.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <QVTKWidget.h>

int main( int argc, char* argv[] ) 
{
    QApplication app(argc, argv);
    QMainWindow window;
    window.addToolBar( new QToolBar( "Tools", &window ) );
    QMenu* menu = window.menuBar()->addMenu("&File");
    menu->addAction("&Quit", &window, SLOT(close()));

    /*
    //**** The normal Qt widget (a button here) repaints fine
    QPushButton hello("Hello world!",&window);
    hello.resize(100, 30);
    window.setCentralWidget( &hello );
    //****
    */

    //**** Works if interacting, but not repainted well
    QVTKWidget* widget = new QVTKWidget( &window );
    widget->resize(256,256);

    vtkPNGReader* reader = vtkPNGReader::New();
    char* fname = "E:/Projects/vtk42/VTKData-release-4-2/Data/vtk.png";
    reader->SetFileName(fname);

    vtkImageViewer* image_view = vtkImageViewer::New();
    image_view->SetInput(reader->GetOutput());

    widget->SetRenderWindow(image_view->GetRenderWindow());
 
image_view->SetupInteractor(widget->GetRenderWindow()->GetInteractor());
    
    window.setCentralWidget( widget );
    //****

    window.show();
    return app.exec();
}

-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On
Behalf Of Wu Ruoyun
Sent: Monday, April 18, 2005 5:07 PM
To: vtkusers at vtk.org
Subject: [vtkusers] QVTKWidget work with Qt 4.0.0 Beta 2?

Dear All,

Has anyone make QVTKWidget work with Trolltech's newly released Qt 4.0.0
Beta 2? I got a number of errors and warnings when compiling.

Best Wishes!
Ruoyun

_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list