Term Dickem
26th May 2010, 15:12
Hi there,
I'm new to Qt and tried to set up a QGLWidget. All went fine but there is a small but annoying error when resizing the QMainWindow in which the QGLWidget is put. I'm rendering a simple cube which can be rotated with the mouse.
But when I increase the size of the window and thus of the QGLWidget, it's not repainted and seems to be frozen even though I call updateGL or paintGL respectively. However it does receive mouse events and stuff. The frozen state remains till I minimize the QGLWidget or till I switch between the tabs of a neighbouring QTabWidget(it's neither a parent nor a child of the QGLWidget).
The problem only occurs when increasing the size of the QGLWidget.
I hope there is some help out there as it seems that noone else had the problem(i googled already a lot)...
I even tried to change focus on other elements in the QMainWindow and then back to the QGLWidget.
I tried to decrease the size of QGLWidget by one pixel.
But these things did not work.
Some code:
void nyGLWidget::initializeGL()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
}
void nyGLWidget::paintGL()
{
qglClearColor(clearColor);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glTranslatef(400.0f, 300.0f, -10.0f);
glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
// draw some objects
glPopMatrix();
}
void nyGLWidget::resizeGL(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,width,height,0,-1000,1000);
glMatrixMode(GL_MODELVIEW);
updateGL();
}
void nyGLWidget::mousePressEvent(QMouseEvent *event)
{
lastPos = event->pos();
}
void nyGLWidget::mouseMoveEvent(QMouseEvent *event)
{
int dx = event->x() - lastPos.x();
int dy = event->y() - lastPos.y();
if (event->buttons() & Qt::LeftButton) rotateBy(8 * dy, 8 * dx, 0);
else if (event->buttons() & Qt::RightButton) rotateBy(8 * dy, 0, 8 * dx);
lastPos = event->pos();
updateGL();
}
void nyGLWidget::mouseReleaseEvent(QMouseEvent * /* event */)
{
emit clicked();
}
I run Qt 4.6.2 on Windows 7 Home Premium(64 bit).
The project is compiled and programmed in Qt Creator 1.3.1 (32 bit).
Thanking you in anticipation.
With best regards,
Term Dickem.
I'm new to Qt and tried to set up a QGLWidget. All went fine but there is a small but annoying error when resizing the QMainWindow in which the QGLWidget is put. I'm rendering a simple cube which can be rotated with the mouse.
But when I increase the size of the window and thus of the QGLWidget, it's not repainted and seems to be frozen even though I call updateGL or paintGL respectively. However it does receive mouse events and stuff. The frozen state remains till I minimize the QGLWidget or till I switch between the tabs of a neighbouring QTabWidget(it's neither a parent nor a child of the QGLWidget).
The problem only occurs when increasing the size of the QGLWidget.
I hope there is some help out there as it seems that noone else had the problem(i googled already a lot)...
I even tried to change focus on other elements in the QMainWindow and then back to the QGLWidget.
I tried to decrease the size of QGLWidget by one pixel.
But these things did not work.
Some code:
void nyGLWidget::initializeGL()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
}
void nyGLWidget::paintGL()
{
qglClearColor(clearColor);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glTranslatef(400.0f, 300.0f, -10.0f);
glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f);
glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f);
glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f);
// draw some objects
glPopMatrix();
}
void nyGLWidget::resizeGL(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,width,height,0,-1000,1000);
glMatrixMode(GL_MODELVIEW);
updateGL();
}
void nyGLWidget::mousePressEvent(QMouseEvent *event)
{
lastPos = event->pos();
}
void nyGLWidget::mouseMoveEvent(QMouseEvent *event)
{
int dx = event->x() - lastPos.x();
int dy = event->y() - lastPos.y();
if (event->buttons() & Qt::LeftButton) rotateBy(8 * dy, 8 * dx, 0);
else if (event->buttons() & Qt::RightButton) rotateBy(8 * dy, 0, 8 * dx);
lastPos = event->pos();
updateGL();
}
void nyGLWidget::mouseReleaseEvent(QMouseEvent * /* event */)
{
emit clicked();
}
I run Qt 4.6.2 on Windows 7 Home Premium(64 bit).
The project is compiled and programmed in Qt Creator 1.3.1 (32 bit).
Thanking you in anticipation.
With best regards,
Term Dickem.