Results 1 to 20 of 30

Thread: Render QWidget within QGLWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    Thanks Joh ill try the above mentioned when i get back from work

    speaking of which, i tried to run the qq26-openglcanvas program on an Ubuntu 10.04 PC with Qt 4.6.2 and this code runs fine. howcome?

    BTW my home PC is Windows 7 using Qt 4.7.0

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    I guess your Ubuntu only supports/has drivers for OpenGL 1.0.
    Happy coding

  3. The following user says thank you to JohannesMunk for this useful post:

    crazymonkey (18th September 2010)

  4. #3
    Join Date
    Sep 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    Thanks Joh, youve helped alot!

    quick question: where do i make my usual updateGL() , resizeGL() and paintGL() calls then?
    Last edited by crazymonkey; 18th September 2010 at 13:02.

  5. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    You don't!

    paintGL => drawBackground
    or if you want individual items, subclass QGraphicsItem implement boundingRect and paintEvent (using either QPainter stuff or native OpenGL calls with QPainter.beginNativePainting() .. )

    http://www.qtcentre.org/threads/34148-Qt-and-OpenGl-(I-m-lost)?p=158675#post158675

    resizeGL => taken care of the view, otherwise subclass QGraphicsView, implement resizeEvent.
    updateGL => not necessary.

    Joh

  6. #5
    Join Date
    Sep 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    and if i want to use listeners to zoom in/out of my openGL scene is it done in the same way as i would normally do it?

  7. #6
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    Yes. You can then update the view either manually (view->update()), when something changes - or periodically with a Timer (fixed framerate), depends.

    Or you split your scene and implement different QGraphicsItems. Call their update() function to trigger a redraw of them.

    Joh

  8. #7
    Join Date
    Sep 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    Sorry and what about initializeGL() ??

    im very noob sorry for all these questions!
    Last edited by crazymonkey; 19th September 2010 at 11:13.

  9. #8
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    InitializeGL. Bit tricky that one.

    Your example http://doc.trolltech.com/qq/qq26-openglcanvas.html doesn't use any opengl initialization. Does it on every repaint.

    drawBackground is called every 20ms due to (view.setViewportUpdateMode(QGraphicsView::FullVie wportUpdate); in main.cpp and QTimer::singleShot(20, this, SLOT(update())); at the end of drawBackground)

    If that's too expensive for you, because you need to setup big displaylists or something like that, you could:

    1) Do one of these: http://stackoverflow.com/questions/1...stom-qglwidget

    2) Have a look at the boxes demo: http://doc.trolltech.com/latest/demos-boxes.html

    3) "Dirty", but efficient Hack:

    Qt Code:
    1. class OpenGLScene : ..
    2. {
    3. private:
    4. bool initialized;
    5. }
    6.  
    7. OpenGLScene::OpenGLScene(..)
    8. {
    9. initialized = false;
    10. }
    11.  
    12. void OpenGLScene::drawBackground(QPainter *painter, const QRectF &)
    13. {
    14. if (initialized == false)
    15. {
    16. // your initialization goes here..
    17. initialized = true;
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 
    Joh
    Last edited by JohannesMunk; 19th September 2010 at 12:47.

  10. #9
    Join Date
    Sep 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    hello Joh im having difficulty in adding new widgets

    i think this is more of a Qt specific question but what command can i use to set the position of my widgets on my scene?

    i have added widgets made via Qt designer perfectly fine. but now i want to make them movable with mouse dragging.

    also my widget doesn't have a title like in the example shown http://doc.trolltech.com/qq/qq26-openglcanvas.html

    how do i make them movable via mouse dragging and how do i show a title (eg "Instructions")

  11. #10
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    Hi!

    You could have looked it up in the example you referred to!

    Qt Code:
    1. QWidget* w = new QWidget();
    2. w->setGeometry(0,0,150,150);
    3. w->setWindowTitle("Title");
    4. QGraphicsProxyWidget* proxy = scene->addWidget(w);
    5. proxy->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    6. proxy->setPos(10,10);
    To copy to clipboard, switch view to plain text mode 
    Cheers!

    Joh

  12. #11
    Join Date
    Sep 2010
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    sorry i meant how do make it draggable across the scene?

  13. #12
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Render QWidget within QGLWidget

    you can take it and drag it around this way. what else do you want?

Similar Threads

  1. Replies: 1
    Last Post: 7th May 2010, 17:20
  2. QGLWidget Render Text in the foreground
    By arpspatel in forum Qt Programming
    Replies: 1
    Last Post: 11th April 2010, 11:35
  3. How to render the contents of QPrinter to QWidget
    By nifei in forum Qt Programming
    Replies: 0
    Last Post: 6th March 2009, 04:25
  4. QWidget::render with DrawChildren flag
    By Apocalypse in forum Qt Programming
    Replies: 4
    Last Post: 4th January 2009, 22:15
  5. QWidget::render() and sharedPainter
    By faldzip in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2008, 20:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.