You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, December 6th 2011, 9:22pm

Subclassing paintGL()

Hello,

my application has a QGraphicsView with inside a QGraphicsScene that hosts a widget. The viewport of the QGraphicsView is set to a GLWidget.
Ok, I see the widget inside the QGraphicsScene.

Now I want to subclass the paintGL() of the GLWidget. If I paint something in the paintGL() event the QGraphicsScene disappear. Calling its update() method leads to the redraw of the QGraphicsScene loosing what rendered in the viewport background. I tried to call GLWidget::paintGL(); after my code in the paintGL() event without success.

My goal is to render an image in the paintGL() event and then the QGraphicsScene as an "overlay" in the viewport.

What should I do?
Thanks

2

Tuesday, December 6th 2011, 11:01pm

http://doc.trolltech.com/4.6/qgraphicsscene.html#addWidget

Quoted


Creates a new QGraphicsProxyWidget for widget, adds it to the scene, and returns a pointer to the proxy. wFlags set the default window flags for the embedding proxy widget.

The item's position is initialized to (0, 0).

If the item is visible (i.e., QGraphicsItem::isVisible() returns true), QGraphicsScene will emit changed() once control goes back to the event loop.

Note that widgets with the Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller are not supported. Examples are QGLWidget and QAxWidget.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Wednesday, December 7th 2011, 5:54am

The QGLWidget is set as the viewport, it's not a widget added using the addWidget method:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QGraphicsView view;
    view.setViewport(new CustomGLWidget());
    view.setViewportUpdateMode(QGraphicsView::NoViewportUpdate); // tried different options

    QGraphicsScene *s = new QGraphicsScene();
    myWidget *w = new myWidget(); // it's a class based on QWidget that paints something
    s->addWidget(w);    // it could be any ohter QWidget
    view.setScene(s);
    view.resize(800, 600);
    view.show();

    return app.exec();
}


If I paint something in the paintGL() event of the CustomGLWidget() I have the behavior described above.

What I'm trying to do is very simple: draw in the CustomGLWidget() because it's fast and have a standard QPainter on its top to draw an overlay.

4

Wednesday, December 7th 2011, 12:27pm

dont know then.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

5

Wednesday, December 7th 2011, 12:54pm

No problem.
I hope someone may help me. Where do you think I could ask my question?