I want to write my own irrlicht scene editor with QT.
I create a class QIrrlichtWidget which derived from the QWidget, and reimplement the "paintEvent" mehtod to drive the Irrlicht drawing loop.
//.h
class QIrrlichtWidget : public QWidget
{
signals:
void updateIrrlicht( );
public slots:
void autoUpdateIrrlicht();
protected:
virtual void paintEvent ( QPaintEvent * event );
}
//.cpp
QIrrlichtWidget::QIrrlichtWidget(QWidget *parent) : QWidget(parent)
{
connect( this, SIGNAL(updateIrrlicht()), this, SLOT(autoUpdateIrrlicht()) );
}
void QIrrlichtWidget::paintEvent(QPaintEvent *event)
{
if ( m_device )
{
emit updateIrrlicht( m_device );
}
}
void QIrrlichtWidget::autoUpdateIrrlicht()
{
if(m_device->run())
{
m_device->getTimer()->tick();
m_driver->beginScene(true, true, irr::video::SColor(255,125,0,0));
m_scene->drawAll();
m_guienv->drawAll();
m_driver->endScene();
}
}
but the QT throw the "QWidget::repaint: Recursive repaint detected" exception.
so, I use the Qt timer to avoid using the paintEvent.
QIrrlichtWidget::QIrrlichtWidget(QWidget *parent) : QWidget(parent)
{
connect( this, SIGNAL(updateIrrlicht()), this, SLOT(autoUpdateIrrlicht()) );
startTimer(0);
}
void QIrrlichtWidget::timerEvent(QTimerEvent * event)
{
if ( m_device )
{
emit updateIrrlicht( m_device );
}
event->accept();
}
http://ww1.sinaimg.cn/large/a011c7abgy1g09hl7t6e1j20x10jy3zr.jpg
It is works well. But, there are still some problems. When I pass the QT mouse events to irrlicht engine, and operate the objects in irrlicht scene, the user experience is too bad. There are some delays that cannot be tolerated.
So, do anyone have any good ideas to solve the problem?