Trolltech Home | Qt4-preview-feedback Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt4-preview-feedback Archive, February 2007
QPainter over QGLWidget.?


Message 1 in thread

Hi ,



I succeed to put the COIN 3d scene graph contents in the QGLWidget. But 
after that I can not draw with QPainter over it as usual.   Does anybody has 
answer of that?



Thanks



Julian



Here some dummy source.



#include <Inventor/Qt/SoQt.h>

#include <Inventor/Qt/SoQtRenderArea.h>

#include <Inventor/nodes/SoCone.h>

#include <Inventor/nodes/SoDirectionalLight.h>

#include <Inventor/nodes/SoPerspectiveCamera.h>

#include <Inventor/nodes/SoSeparator.h>

#include <QGLWidget>

#include <QPainter>

#include <QApplication>





class MyGLView : public QGLWidget {

public:

      MyGLView(QWidget * parent) : QGLWidget(parent)

            {





            // Container widget for the SoQtRenderArea.



            QWidget * container = new QWidget(this);

            container->resize(300,300);



            // Construct a simple scenegraph.



            SoSeparator * root = new SoSeparator;



            SoDirectionalLight * light = new SoDirectionalLight;

            light->direction.setValue(-0.5, -0.5, -0.8);

            root->addChild(light);



            SoPerspectiveCamera * camera = new SoPerspectiveCamera;

            camera->orientation = SbRotation(SbVec3f(0, 0, 1), 0);

            root->addChild(camera);



            SoCone * cone = new SoCone;

            root->addChild(cone);



            // Add the renderarea.



            SoQtRenderArea* renderarea = new SoQtRenderArea(container);

            renderarea->setSceneGraph(root);

            camera->viewAll(root, renderarea->getViewportRegion());





            }



protected:



      void paintEvent(QPaintEvent *event)

            {

             QPainter p(this);



             p.setBrush(Qt::cyan);

             p.setPen(Qt::darkCyan);

             p.drawRect(250, 250, 100,100);



             }

private:

      SoQtRenderArea * renderarea;

      };



/***********************************************************************/



int

main(int argc, char ** argv)

      {

      // Initialize Qt and SoQt.

      QApplication app(argc, argv);

      SoQt::init((QWidget *)NULL);



      // Set up scrollview window.

      MyGLView * vp = new MyGLView(NULL);



      // Map window.

      vp->show();

      // Set termination condition.

      QObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, 
SLOT(quit()));

      // Start event loop.

      SoQt::mainLoop();



      return 0;

      }


To unsubscribe - send "unsubscribe" in the subject to qt4-preview-feedback-request@xxxxxxxxxxxxx