0

Initially, I followed the structure of http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt. I created a vanilla Visual Studio 2010 Qt application project, clicked on the .ui file to start Qt Designer, inserted a QWidget and promoted it to myglwidget. I then created a myglwidget subclass of QGLWidget.

That worked fine, and I got my red triangle.

The issue is that myglwidget doesn't get any of the resize events when the main window is resized, even if I set the widget size properties to "expanding."

And when I restructure my app constructor to call setCentralWidget(&myglwidget_) the code compiles and runs but no OpenGL window appears.

I'm not seeing how to resize my widget to match the main window size. I'm also not understanding why the setCentralWidget approach didn't work.

I believe I know how to solve the problem by writing explicit Qt code, but that defeats the purpose of my trying to build an OpenGL app in Qt using Qt Designer.

Walt Donovan
  • 357
  • 1
  • 10

1 Answers1

0

The following code for the application "baz6" fixes the problem. The code I inserted in the wizard-generated code is flagged with //***

baz6.h:

#ifndef BAZ6_H
#define BAZ6_H

#include <QtGui/QMainWindow>
#include "ui_baz6.h"
#include "myglwidget.h"        //***

#include <QResizeEvent>

class baz6 : public QMainWindow
{
    Q_OBJECT

public:
    baz6(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~baz6();

private:
    Ui::baz6Class ui;
    myGLWidget *myglwidget_;      //***
};

#endif // BAZ6_H

baz6.c:

#include "baz6.h"
#include "myglwidget.h"

baz6::baz6(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
{
    ui.setupUi(this);

    myglwidget_ = new myGLWidget();      //***
    setCentralWidget(myglwidget_);       //***
}

baz6::~baz6()
{

}

Previously, I had not explicitly constructed the myGLWidget.

Matthias
  • 7,432
  • 6
  • 55
  • 88
Walt Donovan
  • 357
  • 1
  • 10