[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:
- qmlRegisterType<Video>(uri,1,0,"Video");
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))
- {
- Q_D(Video);
- 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:
- {
- Q_UNUSED(painter);
- Q_UNUSED(widget);
- Q_UNUSED(option);
- Q_D(Video);
- // 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:
- {
- Q_OBJECT
- public:
- ~GLWidget();
- };
Seems pretty simple. Now, the implementation of QGLWidget is the following:
- {
- // Should I do something here?
- // Maybe setAutoFillBackground(false); ???
- }
- GLWidget::~GLWidget()
- {
- }
And finally:
- {
- // I ignore painter because it comes from Video, so I create a new one:
- // 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),
- scaled_img);
- }
What am I missing?
2 replies
The answer for this question is here [stackoverflow.com].
You must log in to post a reply. Not a member yet? Register here!


