PDA

View Full Version : QGLWidget trouble



John82
30th July 2009, 10:11
Hi

I created a simple GUI with a splitter as a main widget. The splitter holds 3 widgets : A tab widget, a QGLWidget and a QLabel to display image files. Initially the QLabel is hidden and the QGLWidget is displayed.
My problem is this : When I switch between the QGLWidget and the QLabel ( using slots to hide / show to switch between them), my QGLWidget does not show any graphics after switching. I have tried refreshing, update etc. Can someone tell me what is happening?

Thanks

yogeshgokul
30th July 2009, 10:54
Can you call :

yourGLWidget->updateGL()

John82
30th July 2009, 11:10
I tried that. The QGLWidget is still blank.

ricardo
30th July 2009, 18:15
Maybe you have your "camera" (or modelview matrix) in a wrong place. Maybe your projection matrix is wrong...

What do you see without any other components? Is it working in that case?

John82
30th July 2009, 18:57
Maybe you have your "camera" (or modelview matrix) in a wrong place. Maybe your projection matrix is wrong...

What do you see without any other components? Is it working in that case?

The graphics works properly when I load a model but when I switch to another widget ( myGLWidget->hide (); myLabel->show (); ) and then switch back to the QGLWidget ( myGLWidget->show (); myLabel->hide (); ); the QGLWidget does not display what was being displayed earlier.

Is there something happening that I am not taking care of?

ricardo
30th July 2009, 19:28
Can we see your code?

John82
30th July 2009, 19:51
The actual code is a little long but here is pseudo code :

myWindow::QMainWindow -> main window

mySplitter::QSplitter -> central widget to myWindow

myWidget::QWidget -> Widget 1

myGLWidget::QGLWidget -> Widget 2 // Shown by default

myLabel::QLabel -> Widget 3 // Hidden by default

// Add Widget 1, Widget 2. Widget 3 to mySplitter

// myWidget has a QTabWidget as a child widget with 2 tabs. On the tab change signal, I have a slot based on the index which does this :

if ( index == 0 ) {
myGLWidget->show ();
myLabel->hide ();
}

if ( index == 1 ) {
mGLWidget->hide();
myLabel->show ();
}

//-------------------------------------------------------------------------------------------
On running the app, it loads a model and the myGLWidget displays graphics properly, but when I switch between tabs, on switching back to myGLWidget the graphics remains blank. :(

ricardo
30th July 2009, 22:11
Can I see your methods paintGL and resizeGL and and how do you manage GL_PROJECTION and GL_MODELVIEW matrices?

john_god
30th July 2009, 23:46
Are you working on windows or linux ? Is the behavior identical in both plataforms ?
There are some limitations on windows plataform when you have several qglwidgets, just read carefully the documentation. I had a class with 3 qglwidget who would not display in windows but worked fine in linux

John82
31st July 2009, 02:03
Are you working on windows or linux ? Is the behavior identical in both plataforms ?
There are some limitations on windows plataform when you have several qglwidgets, just read carefully the documentation. I had a class with 3 qglwidget who would not display in windows but worked fine in linux

Yes the behaviour is identical on both platforms and there is only one QGLWidget.
I put some trace comments in the graphics code and it has thrown up some interesting output.
When the QGLWidget is displayed again, it calls the resizeGL function and while setting up my projection matrix with previously stored values, the near and far values are getting screwed up. So does some other camera parameter values. I am wondering if this is somehow related to a QGLContext problem.