[Solved] Rendering QImage on QGLWidget of QML plugin
I’m trying to write a QML plugin that reads frames from a Video (using a custom widget and NOT QtMultimedia/Phonon), then each frame is converted to a QImage with format RGB888, and then displayed on a QGLWidget. Right now nothing seems to be draw on the screen (the screen stays white).
It’s important to state that I already have all of this working without QGLWidget, so I know the issue is setting up and drawing on QGLWidget.
The plugin is being registered with:
so Video is the main class of the plugin. On it’s constructor we have:
- Video::Video(QDeclarativeItem* parent)
- : QDeclarativeItem(parent), d_ptr(new VideoPrivate(this))
- setFlag(QGraphicsItem::ItemHasNoContents, false);
- QDeclarativeView* view = new QDeclarativeView;
- view->setViewport(&d->canvas()); // canvas() returns a reference to my custom OpenGL Widget
Before I jump to the canvas object, let me say that I overloaded Video::paint() so it calls canvas.paint() while passing QImage as parameter, I don’t know if this is the right way to do it so I would like some advice on this:
- // I know for sure at this point "d->image()" is valid, but I'm hiding the code for clarity
- d->canvas().paint(painter, option, d->image());
The canvas object is declared as GLWidget canvas; and the header of this class is defined as:
Seems pretty simple. Now, the implementation of QGLWidget is the following:
- GLWidget::GLWidget(QWidget* parent)
- // Should I do something here?
- // Maybe setAutoFillBackground(false); ???
- // I ignore painter because it comes from Video, so I create a new one:
- QPainter gl_painter(this);
- // Perform drawing as Qt::KeepAspectRatio
- gl_painter.drawImage(qRound(this->width()/2) - qRound(scaled_img.size().width()/2),
- qRound(this->height()/2) - qRound(scaled_img.size().height()/2),
What am I missing?