[Qt-interest] QGLWidget: initializeGL not executed
Samuel Rødal
sroedal at trolltech.com
Thu May 28 11:53:17 CEST 2009
Oliver Demetz wrote:
> Hi!
>
> I've got a QGraphicsView and scene, and the viewport of my vie is an
> QGLWidget. Everything works fine, also I am sure that the OpenGL
> subsystem is definitely used.
>
> Now I want to use my own subclassed QGLWidget as the viewport in order
> to check some properties of the opengl subsystem:
>
> Instead of
>
> my_view.setViewport(new QGLWidget(...));
>
> I state
>
> my_view.setViewport(new GLWidget(...));
>
> where my GLWidget is:
>
> class GLWidget : public QGLWidget
> {
> public:
> GLWidget(const QGLFormat & format, QWidget * parent = 0, const
> QGLWidget * shareWidget = 0, Qt::WindowFlags f = 0 )
> : QGLWidget(format, parent, shareWidget, f)
> {
>
> }
> protected:
> void glInit()
> {
> QGLWidget::glInit();
> qDebug() << "glinit";
> }
> void initializeGL()
> {
> QGLWidget::initializeGL();
>
> QString strextensions((char*)glGetString(GL_EXTENSIONS));
> QStringList extlist = strextensions.split(" ");
> foreach(QString s, extlist)
> qDebug() << s;
>
> }
> };
>
> If I execute the code, I would expect to see at least the list of
> extensions or the debugstring "glinit".
>
> BUT NOTHING APPEARS!!!
> why are thos methods not executed?????
>
> Note that the functionality still is as it was with the original QGLWidget!
> Only the functions are not executed (also not paintGL).
>
> Thanks in advance,
> Olli
Hello,
initializeGL() etc are called by the default paintEvent() in QGLWidget.
When a QGLWidget is used as a viewport in a QGraphicsView then
QGLWidget::paintEvent() never gets called, as QGraphicsView does the
painting in its paintEvent().
Instead you can call initializeGL() on your own right after creating the
widget, like this:
GLWidget *viewport = new GLWidget(...);
my_view.setViewport(viewport);
viewport->makeCurrent();
viewport->initializeGL();
You'll need to make initializeGL() public, or alternatively create a
different public function that does the initialization.
Regards,
Samuel
More information about the Qt-interest-old
mailing list