Results 1 to 7 of 7

Thread: One GL Context Multiple Widgets - Qt 6

  1. #1
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default One GL Context Multiple Widgets - Qt 6

    I'm trying to create multiple OpenGL-capable QWidget's but sharing the same GL context. I tried to use QOpenGLWidget but it creates a GL context for every widget.
    Is it possible to achieve this using QWidget and Create QOpenGLContext manually and associate it with every created QWidget? Any working examples?

    Thanks.

  2. #2
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: One GL Context Multiple Widgets - Qt 6

    I hope my question is clear otherwise I will assume it's not something doable using Qt. Fair enough!

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,065
    Thanks
    286
    Thanked 832 Times in 819 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: One GL Context Multiple Widgets - Qt 6

    Is it possible to achieve this using QWidget and Create QOpenGLContext manually and associate it with every created QWidget?
    QOpenGLContext::setShareContext() won't do what you want?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  4. #4
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: One GL Context Multiple Widgets - Qt 6

    Quote Originally Posted by d_stranz View Post
    QOpenGLContext::setShareContext() won't do what you want?
    Not really. Once QOpenGLWidget is instantiated, a GL context is created for the widget and cannot be used for subsequent instances of QOpenGLWidget.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,065
    Thanks
    286
    Thanked 832 Times in 819 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: One GL Context Multiple Widgets - Qt 6

    If you create the widget, call its method to retrieve the context, then call setShareContext() with that pointer using your common context, that doesn't work?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #6
    Join Date
    Apr 2010
    Posts
    152
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: One GL Context Multiple Widgets - Qt 6

    Quote Originally Posted by d_stranz View Post
    If you create the widget, call its method to retrieve the context, then call setShareContext() with that pointer using your common context, that doesn't work?
    Then the default created context has to be deleted and the shared context is assigned to every new widget, assuming setShareContext changes the widget context. But this sounds like a hack!

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,065
    Thanks
    286
    Thanked 832 Times in 819 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: One GL Context Multiple Widgets - Qt 6

    But this sounds like a hack!
    Don't know; I don't write explicit OpenGL code that much. I think your only option is to look at the implementation of QOpenGLWidget and then derive your own version from QWidget that lets you set the context externally instead of creating it by default. With luck you may be able to reuse a lot of the source code.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Communication with multiple MDI widgets
    By dan3460 in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2017, 21:23
  2. Replies: 1
    Last Post: 2nd October 2012, 02:38
  3. Multiple Views One GL Context
    By qtoptus in forum Qt Programming
    Replies: 1
    Last Post: 5th December 2010, 23:23
  4. Qt3 - Multiple transparent widgets
    By bythesea in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2009, 12:24
  5. Multiple Context Menus
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 24th December 2008, 20:55

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.