PDA

View Full Version : how do you use a QGLWidget in a QAbstractItemView?



Gravis
6th December 2009, 18:51
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? :crying:

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

wysota
7th December 2009, 08:36
Hard to say without seeing any code.

Gravis
7th December 2009, 10:29
Hard to say without seeing any code.

It's quite basic. Here are the important bits (unless you want to see the drawing code).


GlWindow::GlWindow()
: QMainWindow()
{
// GLBox* c = new GLBox(this); // <-- displays properly
GLItemView* c = new GLItemView(this); // <-- doesnt display properly
setCentralWidget(c);
}


GLItemView::GLItemView(QWidget* parent)
: QAbstractItemView(parent)
{
GLBox* box = new GLBox(parent);
setViewport(box);
}

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

wysota
7th December 2009, 10:44
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).

Gravis
7th December 2009, 18:38
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. ;)

wysota
8th December 2009, 08:17
The functionality has to be implemented in the view, not it's viewport. Period.