Hi there! I am stuck with a very basic problem with the QGLWidget. The space of the widget is just black, the overwritten methods of my own subclass of QGLWidget, initializeGL resizeGL paintGL, are never called (checked with breakpoints).
So I went back to the Hello GL example, which works correctly. But I can't find noticable difference to the Hello GL example. There the resizeGL gets called with the show() of the window widget. In my program the method is NOT called.
What am I missing so the xGL methods of MyGLViewer get called?
main.cpp
#include <QtGui/QApplication>
#include "WindowWidget.h"
int main(int argc, char *argv[])
{
WindowWidget w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "WindowWidget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
WindowWidget w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
my window class WindowWidget, that does nothing but to add the ogl-widget.
#include "WindowWidget.h"
#include "ui_WindowWidget.h"
WindowWidget
::WindowWidget(QWidget *parent
) : QWidget(parent
), ui
(new Ui
::WindowWidget) { ui->setupUi(this);
viewer = new MyGLViewer(this);
layout->addWidget(viewer);
setLayout(layout);
}
WindowWidget::~WindowWidget() { delete ui; }
---
#ifndef WINDOWWIDGET_H
#define WINDOWWIDGET_H
#include <QWidget>
#include "MyGLViewer.h"
namespace Ui { class WindowWidget; }
class WindowWidget
: public QWidget { Q_OBJECT
public:
explicit WindowWidget
(QWidget *parent
= 0);
~WindowWidget();
protected:
Ui::WindowWidget *ui;
MyGLViewer* viewer;
};
#endif // WINDOWWIDGET_H
#include "WindowWidget.h"
#include "ui_WindowWidget.h"
WindowWidget::WindowWidget(QWidget *parent) : QWidget(parent), ui(new Ui::WindowWidget) {
ui->setupUi(this);
viewer = new MyGLViewer(this);
QHBoxLayout* layout = new QHBoxLayout();
layout->addWidget(viewer);
setLayout(layout);
}
WindowWidget::~WindowWidget() { delete ui; }
---
#ifndef WINDOWWIDGET_H
#define WINDOWWIDGET_H
#include <QWidget>
#include "MyGLViewer.h"
namespace Ui { class WindowWidget; }
class WindowWidget : public QWidget {
Q_OBJECT
public:
explicit WindowWidget(QWidget *parent = 0);
~WindowWidget();
protected:
Ui::WindowWidget *ui;
MyGLViewer* viewer;
};
#endif // WINDOWWIDGET_H
To copy to clipboard, switch view to plain text mode
my QGLWidget subclass with method stubs. I check if they are called with breakpoints.
#ifndef MYGLVIEWER_H
#define MYGLVIEWER_H
#include <QGLWidget>
#include <QtOpenGL>
Q_OBJECT
public:
protected:
void initializeGL() {
// Set up the rendering context, define display lists etc.:
...
}
void resizeGL(int w, int h) {
// setup viewport, projection etc.:
...
}
void paintGL() {
// draw the scene:
...
}
};
#endif // MYGLVIEWER_H
#ifndef MYGLVIEWER_H
#define MYGLVIEWER_H
#include <QGLWidget>
#include <QtOpenGL>
class MyGLViewer : public QGLWidget {
Q_OBJECT
public:
MyGLViewer(QWidget *parent=0) : QGLWidget(parent) {}
protected:
void initializeGL() {
// Set up the rendering context, define display lists etc.:
...
}
void resizeGL(int w, int h) {
// setup viewport, projection etc.:
...
}
void paintGL() {
// draw the scene:
...
}
};
#endif // MYGLVIEWER_H
To copy to clipboard, switch view to plain text mode
Bookmarks