Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. QGLWidget and QGraphicsScene Program Crash
QtWS25 Last Chance

QGLWidget and QGraphicsScene Program Crash

Scheduled Pinned Locked Moved C++ Gurus
6 Posts 3 Posters 4.8k Views
  • 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.
  • C Offline
    C Offline
    cazador7907
    wrote on last edited by
    #1

    I've been experimenting with rendering a QGLWidget within a QGraphicsScene. The program compiles just fine. However, when I attempt to render some text to the middle of the widget, the program will run for about a second and then it crashes. I've narrowed the problem down to the paintGL method (code below). However, I can't figure out why it's crashing.

    //Main
    @
    QGraphicsScene scene;
    scene.setSceneRect(0,0, 800, 600);
    scene.setItemIndexMethod(QGraphicsScene::NoIndex);
    scene.addWidget(new BackGroundGLWidget());

    QGraphicsView view(&scene);
    view.setMaximumSize(800, 600);
    view.setAlignment(Qt::AlignCenter);
    view.showMaximized();
    view.show();
    

    @

    PaintGL Code
    @
    // Clear screen and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity(); // Reset view matrix
    glTranslatef(0.0f, 0.0f, -1.0f); // Move into screen 1 unit
    
    // Pulsing colors based on text position
    glColor3f(qMax(0.0, 1.0f * cos(cnt1)),
              qMax(0.0, 1.0 * sin(cnt2)),
              qMin(1.0, 1.0f - 0.5f * cos(cnt1 + cnt2)));
    
    // Print text on the screen
    QFont font;
    font.setBold(true);
    font.setPixelSize(18);
    
    // Print some text without taking the transformation into account
    // Very useful class to align some text in OpenGL at the absolute
    // borders of the screen!
    QFontMetrics metrics(font);
    QString bottomRightText("I am always at the bottom right.");
    renderText((width() - metrics.width(bottomRightText) - 10)/2,
               (height() - metrics.height() + 10)/2, bottomRightText, font);
    

    @

    Laurence -

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      renderText is buggy at best (and about to be obsoleted). Try removing that call and see whether it crashes...

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        You can't put a QGLWidget inside a QGraphicsScene because it paints on screen.

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cazador7907
          wrote on last edited by
          #4

          So, how would I set a jpg image as overlay dialogs, buttons, lines and the like?

          Laurence -

          Laurence -

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #5

            Hm, you should do setViewport(new QGLWidget) on your graphics view. That enables you to do opengl stuff in your scene.

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dangelog
              wrote on last edited by
              #6

              [quote author="cazador7907" date="1296309277"]
              So, how would I set a jpg image as overlay dialogs, buttons, lines and the like?

              Laurence -

              [/quote]

              I'm not getting it... do you have all of that in a QGraphicsScene or as ordinary widgets? Where and how is OpenGL involved in this?

              Software Engineer
              KDAB (UK) Ltd., a KDAB Group company

              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