Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    QGLWidget's child widgets

    General and Desktop
    4
    10
    5553
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      Latexi95 last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • B
        baysmith last edited by

        Can you provide a small example which shows the problem?

        Nokia Certified Qt Specialist.

        1 Reply Last reply Reply Quote 0
        • L
          Latexi95 last edited by

          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();
          }@

          1 Reply Last reply Reply Quote 0
          • B
            broadpeak last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • V
              veeeee_d last edited by

              [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?

              1 Reply Last reply Reply Quote 0
              • L
                Latexi95 last edited by

                [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.

                1 Reply Last reply Reply Quote 0
                • B
                  broadpeak last edited by

                  [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!

                  1 Reply Last reply Reply Quote 0
                  • L
                    Latexi95 last edited by

                    [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.

                    1 Reply Last reply Reply Quote 0
                    • B
                      broadpeak last edited by

                      [quote author="Latexi95" date="1323272853"]
                      they aren't QGLWidget's child widgets
                      [/quote]

                      Ahhhh!
                      Yes, you are right!
                      I have missread the text.
                      Sorry...

                      1 Reply Last reply Reply Quote 0
                      • B
                        baysmith last edited by

                        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.

                        Nokia Certified Qt Specialist.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post