QGLWidget's child widgets
-
I'm trying to add child widgets for QGLWidget, so I could make menus for my game, but I get "QPainter::begin: Paint device returned engine == 0, type: 1" every time QGLWidget paints itself. I thought that QGLWidget supports child widgets?
How could I fix this problem?Sorry about bad English.
-
Sorry.
Maybe my explanation was ambiguous. This examble shows clearly what I was trying to explain.
If I use QWidget, everything will work fine. But when I use QGLWidget, I will see white box or my desktop in place of QPushButton. Am I doing something wrong or is it "feature" that I just didnät find out reading QGLWidget's documentation.@#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtGui/QPushButton>class Window: public QGLWidget
{
public:
Window(QWidget *parent = 0):QGLWidget(parent)
{
QPushButton *button = new QPushButton(this);
button->setGeometry(QRect(10,10,100,40));
button->setText("Button");
}};
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Window window;
window.show();
return a.exec();
}@ -
Hm... This code snippet is not so perfect.
Read this excerpt:
http://doc.qt.nokia.com/latest/opengl-hellogl.html
What is important for you:the createSlider() function declaration and definition in the *.h and in the *.cpp files. -
[quote author="broadpeak" date="1323268971"]Hm... This code snippet is not so perfect.
Read this excerpt:
http://doc.qt.nokia.com/latest/opengl-hellogl.html
What is important for you:the createSlider() function declaration and definition in the *.h and in the *.cpp files.[/quote]Huh?
-
[quote author="broadpeak" date="1323268971"]Hm... This code snippet is not so perfect.
Read this excerpt:
http://doc.qt.nokia.com/latest/opengl-hellogl.html
What is important for you:the createSlider() function declaration and definition in the *.h and in the *.cpp files.[/quote]
Sliders aren't QGLWidget's child widgets in that example. Window is QWidget and it has QGLWidget and three QSliders as child widgets. -
[quote author="Latexi95" date="1323270863"]
Sliders aren't QGLWidget's child widgets
[/quote]Sliders ARE child widgets, because of these:
@
mainLayout->addWidget(xSlider);
...
setLayout(mainLayout);
@
These two lines will automatically re-parent the widget! -
[quote author="broadpeak" date="1323271285"]
Sliders ARE child widgets, because of these:
@
mainLayout->addWidget(xSlider);
...
setLayout(mainLayout);
@
These two lines will automatically re-parent the widget![/quote]
Yes. They are child widgets, but they aren't QGLWidget's child widgets.
mainLayout is layout of Window and Window is QWidget. -
While the Qt documentation is very good, it does not cover everything.
A QGLWidget can't have children widgets. The way a QGLWidget paints and the way other QWidgets paint don't work together automatically. While it is possible to "paint":http://doc.qt.nokia.com/latest/opengl-overpainting.html and "embed widgets":http://doc.qt.nokia.com/qq/qq26-openglcanvas.html, it can't be done by simply adding a child QWidget, and the other mechanisms come with performance consequences.