Controlling GL widget within QT
-
I am working at home on Windows and at work on Linux. This is at work. I am a novice at QT and OpenGL, don’t understand all I am trying now, and cannot copy paste from my work computer to this forum so please try to accommodate typos.
I have created a QT dialog and incorporated a GL widget in it, but cannot set the color or properly control the size. So far I can display a QT widget with: a label and a Quit button in a Horizontal layout box. That layout box is then placed in a vertical layout box along with the widget described just below. The GL widget has random bits displayed, and is a fixed size. My immediate milestones are: clear to black and be resizable.
Here is the GL widget with some of the later attempts commented out.C_gl_widget::C_gl_widget( QWidget * parent, const char *name ) : QGLWidget( parent, name ) { SetFormat( QGLFormat( DoubleBuffer | DepthBuffer ) ); // qglClearColor( 0.0, 0.0, 0.0, 0.0 ); // no matching function call // glclearColor( black ); // not declared in this scope // glclearColor( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // won’t compile // glClear( 1 ); // setSizePolicy( QSizePolicy::MinimumExpanding ); // The line above will not make, The error message lists three of the QT include files and // concludes with: QSizePolicy::QSizePolicy(int) is private. SetMinimumjSize( 300, 400 ); // works, but cannot change the size at run time. }
Question for the GL widget: What code will set the color to black? What code will cause it to be resizable?
-
Hi,
Since it's a new project, you should use QOpenGLWidget. There's an example in the details of the class that will get you started.
As for the resizing, if you mean the widget itself, it will happen automatically if you put it in a properly applied layout.
-
Hello SGaist,
Thanks for the reply. Here at work, on a government computer and through their firewalls, I the link gives me a network error and a message about how Internet Usage is Logged. I will have to try that at home. I get those so much I just ignore them, except for the part about not being able to see the information needed. I will do some searching for that phrase and other sites that may help.
Thanks again for your time. -
Unless you have some reduced Qt installation, you should have the full documentation at your disposal in Qt Creator.
-
QOpenGLWidget is Qt 5 so you have to stay with QGLWidget, but in any case, the documentation still provides an example on how to get started.
-
QGLWidget is mentioned in the QT3 book. I used it IAW with that book and compared with the QT4 book. We don't have QT5 and should not need it for now. I can create an OpenGL window within a QT dialog. My next milestone is just to clear the screen, but I cannot do that. I need some assistance and hints as to where to look.
-
Just take into account that Qt 4 has reached end of life since a few years already.
Again, the class documentation already shows the basics and links to several examples that should get you going.