Qt World Summit: Register Today!

[merged] qglwidget and layouts problem?

  • hello i have my QGLWidget setup and showing inside my mainlayout but i cant seem to get it showing a black box or anything like for instance when i dont put QGLWidget inside a layout and just show it, it shows a Black Box like it should but how do i get that within the layout and if i could do this i would be able to use it as a form of eye candy :) thanks in advance

  • Remember to set the layout on the parent widget (e.g. the QMainWindow).

  • can you show me an example of that? :) i have no idea lol

    sorry for that

    heres my guess :)
    i set qwidget thats parented which i called MainFrame which is the 'id' then add the method to it which is setlayout on qmainwindow?

    can someone say if thats right or not

  • Yes that is right for a general QWidget parent. If you are using QMainWindow then you can just do:

    mainWindow->setCentralWidget( myGLWidget );

  • awesome so how do i add opengl code to it :)

    god wish the qt book explained it for the newer versions of QT ;l

  • Get an svn checkout of a few simple OpenGL examples that uses QGLWidget from my repository:

    svn co https://svn.theharmers.co.uk/svn/codes/public/opengl/trunk opengl-examples
    cd opengl-examples/06-solar-system

    Basically follow the QGLWidget documentation and override paintGL(), resizeGL(), and initializeGL(). Then override any event handler functions that you need e.g. keyPressEvent( QKeyEvent* e ).

  • these are great for someone who is using C++ as the core code but i much prefer QML way of doing things so how would one do that with QML? :) i just love that hole idea that a gui is run by a unique part and 3D graphics done by another and plus its alot nicer to work with once im very good with QML i will defently look into C++ focused QT for more control if needed for more freedom as i love C++ :) its very nice

  • ?? :)

  • okay so i really didn't want to post again but im very confused :(

    iv got a QML written Application all done by me but i dont understand how to put opengl code into it i have my QGLWidget showing but i dont know where to put the code i know the docuementation is great but only for C++ focused coding and not QML :( so where would one go for QML i like QML but i also like the C++ way of doing it just makes things alot more funner for me using QML any ideas? :) thank you if iv miss read something or iv done something wrong please tell me so its possible that i can learn from it also please tell me how you figure this stuff out because im out of options when it comes to thinking of ways of making things work in QT

  • Please don't double post. You've already asked this question in your "original thread":http://developer.qt.nokia.com/forums/viewthread/8133/ less than two hours ago. Be patient, and someone will reply there if they have an answer for you.

  • Once I came across a code snippet where QGLWidget was embbedded in QML. I think he used somekind of QGraphicsRectangle.

    I'll try to look up the code.

  • Take a look at this, but this isn't the code I found earlier.
    But still might be helpful: "Click here":http://talk.maemo.org/archive/index.php/t-39913.html

  • Thats how you do it with C++ :) i want to do it in QML mostly unless that the only way, if i do then ill otherwise have to rewrite all my QML into C++ / QT way of doing code which is very tedious and i would rather do that in a later update of my application for now i just want things to work and the tutorials to actually work logically :D this is really annoying :((( not at you tho dude just in general finding a decent gui toolkit that has documentation that makes sense is very hard to come by some of the books are nice but they dont explain Opengl with QT in total detail which is very very /inraging :(

  • Ok... maybe we'll discuss it here. :-)

    Outside of some nifty stuff which is still forthcoming, there is no direct OpenGL access available from inside of QML. It all has to be done from the C++ side of things as far as I know. QGLWidget is, by definition, a C++ thing.

    The info that xcoder posted is all about making the QGLWidget coexist with your QDeclarative (QML) display area. That's probably as close as you're going to get at the moment. I don't see where that necessarily requires you to rewrite all of your QML into C++.

  • okay :D then ill do it np :) i just need to know where to place the code and is there any tutorials that explains in good detail i tried using the Orginal QT documentation but its not very detailed with the idea of placement of code inside someone elses abstract code and problems of that nature :)

    wheres the common place to put this code? :) for most people and why? and how do you figure that out and know the reasons?

    please go into detail when answering :]

    if you need my code just ask :)

  • Merged the 2 posts

  • thanks :) lets hope theres an answer to my question with hope }:

  • iv written what QT needs to do a basic 3d graphics render but for some reason i just keep getting errors ??? and these errors are just horrid ones that no one can figure out

    heres what i put i know theres some dots missing but i really dont understand what the point of it is maybe for digits?? Or something whateva but the point is it wont work no matter how many ways i try to do it even with dots! :( maybe because im placing it within some other code?? but that shouldnt effect it at all if the syntax was correct on this piece of code below, its all very confusing and i really would apperciate it if someone could guide me in the right direction and do it in a detailed way :) so i can learn from it

    @ class opengl : public QGLWidget

        opengl(QWidget *parent)
            : QGLWidget(parent) {}
        void initializeGL()
            glClearColor(0.0, 0.0, 0.0, 0.0);
        void resizeGL(int w, int h)
            glViewport(0, 0, (GLint)w, (GLint)h);
        void paintGL()


Log in to reply