S B
S B

Reputation: 8384

Rendering SDL_surface on a QWidget in a platform-independent manner

I have a SDL_surface that plays a video in its own window. I want this window to be rendered on a QWidget. I want a generic solution because my targets are OSX, Windows and Linux.

I've come across 2 solutions summarized as below:

  1. The Window ID hack involves setting SDL_WINDOWID to the QWidget's id so SDL pushes pixels on the QWidget. Here is an Example Qt snippet from a related thread.

    However, this doesn't work on OS X and is not guaranteed to work on all Win and Linux platforms.

  2. Manually copying from non-window SDL_surface to QWidget.

    Found some example code for Gtk+ but nothing for Qt so far. The idea is to push the video to memory and pull it from QWidget. Surely one shouldn't use a QImage to render each frame. So how would one implement this copying?

There are possible duplicate questions but my question is more specific about platform-independence

Upvotes: 3

Views: 1656

Answers (1)

karlphillip
karlphillip

Reputation: 93410

Retrieve the pixels from the SDL_Surface and create a QImage with it, then use a QPainter to draw the QImage on the widget.

Upvotes: 2

Related Questions