0
votes

I have a QGLWidget and I like to attach on top of it a QLabel for some measurement visualization (fps, number of object, etc).

I'd like to keep QGLWidget as clean as possible for further re-using and not use QGLWidget::renderText inside of it but use an external debug interface with those measurement.

For now I have:

    QVBoxLayout *l = new QVBoxLayout;

    this->gl = new MyGLWidget;
    l->addWidget(gl);

    QLabel *fps = new QLabel;
    fps->setText(QString("FPS"));
    fps->setStyleSheet("QLabel { background-color : red; color : blue; }");
    fps->setParent(gl);

    this->setLayout(l);

But nothing appears.. of course if I add the QLabel to the layout with QLayout::addWidget I see it.. but is not what I want..

Some ideas?

1

1 Answers

0
votes

Without being assigned to a layout the widget doesn't know, where it should draw, if you don't tell it explicitly. You must call QWidget::setGeometry explicitly to position it.

However placing regular Qt widgets on top of a QGLWidget has some merits. The QGLWidget actually creates a subwindow parented by the top level window. Regular widgets however don't have their own, deidicated subwindows, which means, that from the point of view of the graphics system they're on the same Z stacking level than the top level window itself. And the QGLWidget's actual subwindow has a higher Z stacking level. Parenting a QLabel to the QGLWidget should place it at the right Z stacking level. But then OpenGL drawing operations are different than Qt drawing operations, so your drawing on the QGLWidget may mess up the QLabel.

Simply spoken, there's a reason why QGLWidget has a function "drawText".