View Full Version : Why paintGL() in QGLWidget is called twice
xiangxw
29th February 2012, 03:22
#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtCore/QDebug>
class GLWidget : public QGLWidget
{
public:
GLWidget(QWidget * parent = 0) : QGLWidget(parent) {}
protected:
void paintGL() // why paintGL() is called twice
{
static int i = 0;
qDebug() << ++i;
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
GLWidget widget;
widget.show();
return app.exec();
}
output:
1
2
ChrisW67
29th February 2012, 04:00
The widget is created with a default location and size. You show it. The widget is painted. The window manager adds window decorations and shifts the client area: the widget is repainted. The window manager decides to move it, the widget is repainted. The exact sequence of events depends on your environment a bit. Feel free to drop a debug message into the showEvent(), moveEvent(), resizeEvent() etc.
Why do you care?
xiangxw
29th February 2012, 04:20
But why paintEvent() in QWidget is called just once?
#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <QtCore/QDebug>
class Widget : public QWidget
{
public:
Widget(QWidget * parent = 0) : QWidget(parent) {}
protected:
void paintEvent(QPaintEvent */*event*/)
{
static int i = 0;
qDebug() << ++i;
}
};
int main(int argc, char **argv)
{
QApplication app(argc, argv);
Widget widget;
widget.show();
return app.exec();
}
Output:
1
wysota
29th February 2012, 09:09
Why do you care?
xiangxw
29th February 2012, 09:41
Why do you care?
I think it should be once. Program will take more resources if the function is called twice.
wysota
29th February 2012, 10:06
I can tell you it is going to be called many many times more once you start doing anything with your program.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.