Results 1 to 6 of 6

Thread: how do you use a QGLWidget in a QAbstractItemView?

  1. #1
    Join Date
    Aug 2009
    Location
    LOL Land
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question how do you use a QGLWidget in a QAbstractItemView?

    I have a model/view that works fine but I want to switch to using a QGLWidget to do the rendering for various reasons. My QGLWidget based class renders fine when used in a normal widget fashion but when I use setViewport to make it the renderer in the QAbstractItemView based class, the viewport shows up blank instead of the contents of the QGLWidget based class.

    What am I doing wrong?

    note: I need to use all the fancy things QAbstractItemView provides, so switching to a different type would be a poor choice.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how do you use a QGLWidget in a QAbstractItemView?

    Hard to say without seeing any code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2009
    Location
    LOL Land
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how do you use a QGLWidget in a QAbstractItemView?

    Quote Originally Posted by wysota View Post
    Hard to say without seeing any code.
    It's quite basic. Here are the important bits (unless you want to see the drawing code).

    Qt Code:
    1. GlWindow::GlWindow()
    2. {
    3. // GLBox* c = new GLBox(this); // <-- displays properly
    4. GLItemView* c = new GLItemView(this); // <-- doesnt display properly
    5. setCentralWidget(c);
    6. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. GLItemView::GLItemView(QWidget* parent)
    2. {
    3. GLBox* box = new GLBox(parent);
    4. setViewport(box);
    5. }
    To copy to clipboard, switch view to plain text mode 

    Images of it working as a normal widget and non-working as a viewport. (full source attached).
    Attached Images Attached Images
    Attached Files Attached Files

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how do you use a QGLWidget in a QAbstractItemView?

    This won't work obviously. Your paintGL() will never be called because QAbstractItemView takes control of the widget. You have to do all the drawing there (you can use GL calls).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2009
    Location
    LOL Land
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how do you use a QGLWidget in a QAbstractItemView?

    Quote Originally Posted by wysota View Post
    This won't work obviously. Your paintGL() will never be called because QAbstractItemView takes control of the widget. You have to do all the drawing there (you can use GL calls).
    Ok... it turns out you can't just call the GL functions (like paintGL) directly or it wont work. However, what does work is making the paintEvent public in the GL Widget and then passing on the paint events.

    If there is a better way to pass along events to the GL widget, please share.
    Last edited by Gravis; 7th December 2009 at 18:52.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: how do you use a QGLWidget in a QAbstractItemView?

    The functionality has to be implemented in the view, not it's viewport. Period.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 17th November 2009, 21:19
  2. QGLWidget trouble
    By John82 in forum Qt Programming
    Replies: 9
    Last Post: 31st July 2009, 01:03
  3. Replies: 1
    Last Post: 23rd April 2009, 09:05
  4. Replies: 1
    Last Post: 21st November 2008, 07:00
  5. QGLWidget on another QGLWiget
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 23rd October 2006, 09:59

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.