Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGLWidget's child widgets
Qt 6.11 is out! See what's new in the release blog

QGLWidget's child widgets

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 6.3k Views 1 Watching
  • 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 Offline
    L Offline
    Latexi95
    wrote on last edited by
    #1

    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
    0
    • B Offline
      B Offline
      baysmith
      wrote on last edited by
      #2

      Can you provide a small example which shows the problem?

      Nokia Certified Qt Specialist.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Latexi95
        wrote on last edited by
        #3

        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
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #4

          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
          0
          • V Offline
            V Offline
            veeeee_d
            wrote on last edited by
            #5

            [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
            0
            • L Offline
              L Offline
              Latexi95
              wrote on last edited by
              #6

              [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
              0
              • B Offline
                B Offline
                broadpeak
                wrote on last edited by
                #7

                [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
                0
                • L Offline
                  L Offline
                  Latexi95
                  wrote on last edited by
                  #8

                  [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
                  0
                  • B Offline
                    B Offline
                    broadpeak
                    wrote on last edited by
                    #9

                    [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
                    0
                    • B Offline
                      B Offline
                      baysmith
                      wrote on last edited by
                      #10

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved